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

时间:2015-05-08 17:03:11

标签: mongodb reactivemongo

我们假设我们需要找到ID为5546329b470000850084a622的用户:

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

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

Mongo shell的等价物将是

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

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

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

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

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

1 个答案:

答案 0 :(得分:1)

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

我不知道,但工作AFAIK:

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