2

这是你在 mongo shell 中得到的:

db.col.find(ObjectId("5571849db1969e0a6eb32731")).pretty()
{   
"_id" : ObjectId("5571849db1969e0a6eb32731"),
    "name" : "Some name",
    "logo" : "Some logo",
    "users" : [
        ObjectId("5571830031c7fc341bc2e105"),
        ObjectId("5571830031c7fc341bc2e107")
    ],
    "admins" : [ ],
    "__v" : 0,
    "steps" : 5782
}

这是我在 rmongo 得到的:

myResult <- mongo.find(Connexion, "db.col", query='ObjectId("5571849db1969e0a6eb32731")')

#Error in mongo.bson.from.JSON(arg) : 
#  Not a valid JSON content: ObjectId("5571849db1969e0a6eb32731")

那么,怎么做才对呢?

以防万一:我已经看过。但是mongolite不支持身份验证(因此不可行),我不明白如何处理第二个答案。如果我尝试

result <- mongo.find(Connexion, "db.col", query=mongo.oid.from.string("5571849db1969e0a6eb32731"))

我明白了

# Error in mongo.bson.from.argument(query) : Can't convert to bson: argument should be one of 'list', 'mongo.bson' or 'character'(valid JSON)
4

1 回答 1

2

这应该有效:

result <- mongo.find(Connexion, "db.col", query=list('_id' = mongo.oid.from.string("5571849db1969e0a6eb32731")))
于 2015-06-18T13:09:02.350 回答