Is there a way to query in RMongo with an ObjectId?
Something like:
results <- dbGetQuery(mongo, "users", "{'_id': 'ObjectId('5158ce108b481836aee879f8')'}")
Perhaps by importing a bson library?
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' }}")
Try the new mongolite package:
library(mongolite)
m <- mongo("users")
m$find('{"_id":{"$oid":"5158ce108b481836aee879f8"}}')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With