by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    dcracauer
    @dcracauer
    Hi - new to KMongo, so far loving it. Trying to figure out how to register a Jackson Module and getting stuck. I'm sure its easy, can anyone help?
    Denis Kilchichakov
    @augur
    Hi Guys! Any ideas how to execute scripts on MongoDB 4.2? As eval() was removed...
    zigzago
    @zigzago
    @augur you can use the shell ( http://pauldone.blogspot.com/2019/05/mongo-shell-script-inside-bash.html ). But with the driver, there is no way to execute scripts anymore I think (see https://jira.mongodb.org/browse/SERVER-20510 )
    dcracauer
    @dcracauer
    @zigzago Thanks! worked great.
    feherrer21
    @feherrer21

    Hi everybody, i'm trying to convert this mongo update many to Kmongo.

    db.evaluationsAnswers.updateMany( { "answers._id": { $in: answerIds } }, { $set:{ "answers.$[].alreadyUsed": true}})

    (answerIds is an input String array)

    I tried this:

    collection.updateMany(
      Projections.computed(EvaluationsAnswers::answers.div(Answer::_id).path(), Projections.computed("\$in", answerIds)),
      set(SetTo(EvaluationsAnswers::answers.div(Answer::alreadyUsed), true)
    )

    But it doesn't work, I believe it is because of the positional update $[].
    Any idea about what i'm doing wrong and how to fix it?

    Thanks in advance.

    feherrer21
    @feherrer21
    Hi after a looong day I found this solution:
    collection.updateMany(
      Projections.computed(EvaluationsAnswers::answers.div(Answer::_id).path(), Projections.computed("\$in", answerIds)),
      set(SetTo(EvaluationsAnswers::answers.colProperty.posOp.div(Answer::alreadyUsed), true)),
      mongoUpdateCallback(expectedCount = answerIds.size.toLong(), handler = handler, logger = logger)
    )
    zigzago
    @zigzago

    @feherrer21 Here is a better solution:

    data class EvaluationAnswer(val answers:List<MyAnswer>)
    data class MyAnswer(val _id:String, val alreadyUsed: Boolean)
    
        fun test() {
            val answerIds:List<String> = listOf("a")
            col.updateMany(
                (EvaluationAnswer::answers / MyAnswer::_id) `in` answerIds,
                setValue(EvaluationAnswer::answers.colProperty.allPosOp / MyAnswer::alreadyUsed, true)
            )
        }

    I'm going to add it in the doc ;)

    zigzago
    @zigzago
    I'm also going to add a shortcut to remove the need of colProperty and mapProperty (in the next version - released soon)
    Luis Miguel Mejía Suárez
    @BalmungSan
    Cool :+1:
    feherrer21
    @feherrer21
    @zigzago nice thank you
    John Grange
    @grangej
    Are there any good examples on how to setup kotlinx serializable ? I am getting the following error : java.lang.NoClassDefFoundError: kotlinx/serialization/builtins/AbstractDecoder
    zigzago
    @zigzago
    @grangej you just have to add kmongo-serialization dependency artifact and annotate the class with @Serializable (in this sample http://litote.org/kmongo/quick-start/#lets-start-coding - the class Jedi). 3 days ago, there was a new kotlinx serialization release that is not compatible with the previous one : if you use kotlin 1.3.61 select kmongo 3.12.1, if you use kotlin 1.3.70 select kmongo 3.12.2. HTH
    John Grange
    @grangej
    @zigzago yes finally after much trial and error I was able to get the versions updated (had to update both serialization and maven-serialization). The frustration came from not knowing if my code was correct in the first place since I couldn't find any example of what it should look like :-)
    zigzago
    @zigzago
    artem-bakuta
    @artem-bakuta

    Hello, maybe somebody can help me, I'm using Mongo Compass request:

    {"orderExpDate":{$gte: new Date(new Date().setHours(new ISODate().getHours(),0,0)), $lte: new Date(new Date().setHours(new ISODate().getHours(),59,59))}}

    and it works correct, but using in Kmongo as col.findOne(//request here//) causes an Exception. What could be wrong ??? Thx

    zigzago
    @zigzago
    @artem-bakuta code sample:
    val date = LocalDateTime.now()
    col.findOne(
                """{"date":{$gte: ${date.truncatedTo(ChronoUnit.DAYS).json}, $lt: ${date.truncatedTo(ChronoUnit.DAYS).plusDays(1).json} } }"""
            )
    artem-bakuta
    @artem-bakuta
    @zigzago thank you, great !
    feherrer21
    @feherrer21

    Hi i need Help to translate this mongo query to kmongo

    "$project" :{
        "skillGroups.groupName": "$skillGroups.groupName",
        "skillGroups.groupOrder": "$skillGroups.groupOrder",
        "skillGroups.skills":{
        "$map":{
          input: "$skillGroups.skills",
          as: "skill",
          in : {
            skillId: "$$skill.skillId",
            importance: "$$skill.importance",
            added:{
              "$in" : [ "$$skill.skillId", "$user.userSkills" ]
            }
          }
        }
      }
    }

    Is posible using Projections.computed() way?

    feherrer21
    @feherrer21

    i was trying to do somethig like this :

            project(
              SkillGroupRequest::groupName from "\$skillGroups.groupName",
              SkillGroupRequest::groupOrder from "\$skillGroups.groupOrder",
              SkillGroupRequest::skills from
                Projections.computed("\$map",
                  Projections.computed("input", "\$skillGroups.skills"),
                  Projections.computed("in",
                      Projections.computed("skillId", "$$skill.skillId"),
                      Projections.computed("importance", EvaluationsAnswers::answers.div(Answer::answerDate)),
                      Projections.computed("added",
                        Projections.computed("\$in", listOf("\$$skill.skillId", "\$user.userSkills"))
                      )
                  )
                )
            )

    but it doesn´t work

    feherrer21
    @feherrer21
    My problem is that i don't have the knowledge to use correctly "$map" in KMongo in this way. has some one any idea please?
    feherrer21
    @feherrer21
    I finally found this solucion for my problem. so i want to shared that here:
    project(
              excludeId(),
              SkillGroupRequest::groupName from "\$skillGroups.groupName",
              SkillGroupRequest::groupOrder from "\$skillGroups.groupOrder",
              SkillGroupRequest::skills from
                Projections.computed("\$map", fields(
                  Projections.computed("input", "\$skillGroups.skills"),
                  Projections.computed("as", "skill"),
                  Projections.computed("in", fields(
                    Projections.computed("skillId", "\$\$skill.skillId"),
                    Projections.computed("importance", "\$\$skill.importance"),
                    Projections.computed("added",
                      Projections.computed("\$in", listOf("\$\$skill.skillId", "\$user.userSkills"))
                    )
                  ))
                ))
            )
    feherrer21
    @feherrer21

    Hi everybody, i'm here again, i have this problem i was trying to translate this mongo to kmongo query:

    Mongo:
    db.clients.updateOne(
       {clientId: "key1"},
       { $set: { "projects.$[pr].positions.$[ps].name": "DONE" } },
       { arrayFilters: [ { "pr.projectId": "proyect1" } , { "ps.positionId": "DevopsChampions" } ]}
    ------------------------------to-------------------------------------
    Kmongo:
       clientCollection.coFindOneAndUpdate(
                    Client::clientId eq "key1",
                    setValue(Client::projects.colProperty.filteredPosOp("pr").div(Project::positions).colProperty.filteredPosOp("ps").div(Position::name), "DONE"),
                    FindOneAndUpdateOptions().arrayFilters(listOf(
                            Projections.computed("pr.projectId", "project1"),
                            Projections.computed("ps.positionId", "DevopsChampions")
                    )),
                    logger
            ) ?: throw  ApiException(ApiError.CLIENT_OR_PROJECT_NOT_FOUND)
    )

    It doesn't work. so do anyone has any example for "positional-filtered", or anyone has any idea what's going wrong in my implementation?
    Thanks

    feherrer21
    @feherrer21
    I forgot to mention that Mongo query works and Kmongo implementation doesn't works.
    feherrer21
    @feherrer21
    Hi it finally works just like i was implemented i don't know if i had a cache problem or something in this way but after i tested my code a couple of times it finally works :D
    zigzago
    @zigzago
    @feherrer21 instead of Projections.computed("ps.positionId", "DevopsChampions") you can write "ps.positionId" from "DevopsChampions"