在 R 中从 mongodb 查询多个 ID

Querying multiple ids from mongodb in R

想在 R 中使用 mongolite 从 mongodb 查询多个 ID。

与此代码等效的内容,但在 R 中(来源:How to get multiple document using array of MongoDb id?)。

db.feed.find({
  "_id" : {
    "$in" : 
      [ObjectId("55880c251df42d0466919268"), 
       ObjectId("55bf528e69b70ae79be35006")
      ]
   }
});

我试过了,但它显示错误:

library( mongolite )

chap_rslt_collectn = mongo( 'chapterresults', db = my_db_name, verbose = T, url = my_mongo_url )


tt = chap_collectn$find( "_id" : { "$in" : {'$oid': "5eb32a19c25a56031bdec249", "5e8a5301266dd92b6b96a4f0"} } )

出现这样的错误:

> tt = chap_collectn$find( "_id" : { "$in" : {'$oid': "5eb32a19c25a56031bdec249", "5e8a5301266dd92b6b96a4f0"} } )
Error: unexpected ',' in "tt = chap_collectn$find( "_id" : { "$in" : {'$oid': "5eb32a19c25a56031bdec249","

试试下面的代码。运算符$oid,类似于mongo中的ObjectId(),必须应用于每个ID

qry <- '{"_id" :{"$in": [{"$oid":"5eb32a19c25a56031bdec249"},{"$oid":"5e8a5301266dd92b6b96a4f0"}]}}'
tt = chap_collectn$find(query = qry)