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
To query data from MongoDB collection, you need to use MongoDB's find() method.
To open up the MongoDB shell, run the mongo command from your server prompt. By default, the mongo command opens a shell connected to a locally-installed MongoDB instance running on port 27017 . Try running the mongo command with no additional parameters: mongo.
MongoDB is the premier NoSQL document database for modern developers working on high-performance applications. With its JSON-like documents, MongoDB is notable for horizontal scaling and load balancing, which offers developers an excellent balance of customization and scalability.
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 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