使用ObjectId查询RMongo [英] Querying RMongo with ObjectId
本文介绍了使用ObjectId查询RMongo的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以使用ObjectId在RMongo中进行查询?
Is there a way to query in RMongo with an ObjectId?
类似的东西:
results <- dbGetQuery(mongo, "users", "{'_id': 'ObjectId('5158ce108b481836aee879f8')'}")
也许通过导入bson库?
Perhaps by importing a bson library?
推荐答案
RMongo的dbGetQuery()
函数期望提供的查询字符串的MongoDB扩展JSON语法.
RMongo's dbGetQuery()
function is expecting MongoDB Extended JSON syntax for the provided query string.
ObjectId("<id>")
的MongoDB扩展JSON等效为{ "$oid": "<id>" }
:
The MongoDB Extended JSON equivalent of ObjectId("<id>")
is { "$oid": "<id>" }
:
results <- dbGetQuery(mongo, "users", "{'_id': { '$oid': '5158ce108b481836aee879f8' }}")
这篇关于使用ObjectId查询RMongo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文