mongo <- mongo.create()
if (mongo.is.connected(mongo)) {
buf <- mongo.bson.buffer.create()
mongo.bson.buffer.append(buf, "age", 22L)
query <- mongo.bson.from.buffer(buf)
# Find the first 100 records
# in collection people of database test where age == 22
mongo.find.all(mongo, "test.people", query, limit=100L)
# shorthand: find all records where age=22, sorted by name,
# and only return the name & address fields:
mongo.find.all(mongo, "test.people", list(age=22),
list(name=1L), list(name=1L, address=1L))
}
Run the code above in your browser using DataLab