I want to get a MongoDB query from R.
With the mongo
shell, I would query with:
db.user.find({age:{$gt:21}})
However, In R-Mongo, I haven't found how to describe this query.
Thanks
I want to get a MongoDB query from R.
With the mongo
shell, I would query with:
db.user.find({age:{$gt:21}})
However, In R-Mongo, I haven't found how to describe this query.
Thanks
If you are using rmongodb (there is a similar package called Rmongo):
r <- mongo.find(mongo, "test.user", list(age=list('$gt'=21L)))
the BSON query object can also be built like so:
buf <- mongo.bson.buffer.create()
mongo.bson.buffer.start.object(buf, "age")
mongo.bson.buffer.append(buf, "$gt", 21L)
mongo.bson.buffer.finish.object(buf)
query <- mongo.bson.from.buffer(buf)
r <- mongo.find("mongo", "test.user", query)
If you are using RMongo, the query would be:
dbGetQuery(mongo, "user","{'age':{'$gt': 21}}}")
The result of dbGetQuery() will be a Data Frame.
I have also written light interface to R of the pymongo package (the official API for python) https://github.com/RockScience/Rpymongo/blob/master/Rpymongo.r It mimics as close as possible the functions and arguments on the official page of the API http://api.mongodb.org/python/current/api/pymongo/collection.html