Querying RMongo with ObjectId

北城余情 提交于 2019-11-30 23:42:59

RMongo's dbGetQuery() function is expecting MongoDB Extended JSON syntax for the provided query string.

The MongoDB Extended JSON equivalent of ObjectId("<id>") is { "$oid": "<id>" }:

 results <- dbGetQuery(mongo, "users", "{'_id': { '$oid': '5158ce108b481836aee879f8' }}")

mongo.oid.from.string {rmongodb}

Create a mongo.oid object ftom a string Package: rmongodb Version: 1.5.3 Description Create from a 24-character hex string a mongo.oid object representing a MongoDB Object ID.

Usage mongo.oid.from.string(hexstr) Arguments hexstr (string) 24 hex characters representing the OID. Note that although an error is thrown if the length is not 24, no error is thrown if the characters are not hex digits; you'll get zero bits for the invalid digits.

Details See http://www.mongodb.org/display/DOCS/Object+IDs

Values

Try the new mongolite package:

library(mongolite)
m <- mongo("users")
m$find('{"_id":{"$oid":"5158ce108b481836aee879f8"}}')
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!