ReactiveMongo:如何使用带有_id的$ in运算符

时间:2021-02-02 02:36:53

Let's suppose we need to find a user whose id is 5546329b470000850084a622:

假设我们需要找到一个id为5546329b470000850084a622的用户:

val selector = Json.parse("""{"_id":{"$oid":"5546329b470000850084a622"}}""")

users.find(selector).map {
  ...
}

The equivalent from the Mongo shell would be

来自Mongo shell的等价物将是

db.users.find( {_id: ObjectId("5546329b470000850084a622") } )

Now let's suppose we need to find the users whose ids are 5546329b470000850084a622, 5546329b470000850084a623, and 5546329b470000850084a624... this is the command from the Mongo shell:

现在让我们假设我们需要找到其ID为5546329b470000850084a622,5556329b470000850084a623和5546329b470000850084a624的用户......这是来自Mongo shell的命令:

db.users.find( {_id: {$in: [ObjectId("5546329b470000850084a622"), ObjectId("5546329b470000850084a623), ObjectId("5546329b470000850084a624)"]}})

What is the equivalent JSON for ReactiveMongo? This one?

ReactiveMongo的等效JSON是什么?这个?

{
  "_id" : {
    "$oid" : {
      "$in" : [ "5546329b470000850084a622", "5546329b470000850084a623", "5546329b470000850084a624" ]
    }
  }
}

1 个解决方案

#1


{"$oid":"5546329b470000850084a622"} is the JSON representation of the same thing as ObjectId("5546329b470000850084a622") in the mongo shell. See http://docs.mongodb.org/manual/reference/mongodb-extended-json/#oid

{“$ oid”:“5546329b470000850084a622”}是与mongo shell中的ObjectId(“5546329b470000850084a622”)相同的JSON表示。见http://docs.mongodb.org/manual/reference/mongodb-extended-json/#oid

I don't know , but this should work AFAIK:

我不知道reactivemongo,但这应该适用于AFAIK:

{
  "_id" : {
      "$in" : [ {"$oid": "5546329b470000850084a622"},
                {"$oid": "5546329b470000850084a623"},
                {"$oid": "5546329b470000850084a624"} ]
  }
}

#1


{"$oid":"5546329b470000850084a622"} is the JSON representation of the same thing as ObjectId("5546329b470000850084a622") in the mongo shell. See http://docs.mongodb.org/manual/reference/mongodb-extended-json/#oid

{“$ oid”:“5546329b470000850084a622”}是与mongo shell中的ObjectId(“5546329b470000850084a622”)相同的JSON表示。见http://docs.mongodb.org/manual/reference/mongodb-extended-json/#oid

I don't know , but this should work AFAIK:

我不知道reactivemongo,但这应该适用于AFAIK:

{
  "_id" : {
      "$in" : [ {"$oid": "5546329b470000850084a622"},
                {"$oid": "5546329b470000850084a623"},
                {"$oid": "5546329b470000850084a624"} ]
  }
}