Description Usage Arguments Details Value See Also Examples
Find records in a collection that match a given query.
1 2 | mongo.find(mongo, ns, query = mongo.bson.empty(), sort = mongo.bson.empty(),
fields = mongo.bson.empty(), limit = 0L, skip = 0L, options = 0L)
|
mongo |
(mongo) a mongo connection object. |
ns |
(string) namespace of the collection from which to find records. |
query |
(mongo.bson) The criteria with which to match the records to be found. The default of mongo.bson.empty() will cause the the very first record in the collection to be returned. Alternately, Alternately, |
sort |
(mongo.bson) The desired fields by which to sort the returned records. The default of mongo.bson.empty() indicates that no special sorting is to be done; the records will come back in the order that indexes locate them. Alternately, Alternately, |
fields |
(mongo.bson) The desired fields which are to be returned from the matching record. The default of mongo.bson.empty() will cause all fields of the matching record to be returned; however, specific fields may be specified to cut down on network traffic and memory overhead. Alternately, Alternately, |
limit |
(as.integer) The maximum number of records to be returned. A limit of 0L will return all matching records not skipped. |
skip |
(as.integer) The number of matching records to skip before returning subsequent matching records. |
options |
(integer vector) Flags governing the requested operation as follows:
|
See http://www.mongodb.org/display/DOCS/Querying.
(mongo.cursor) An object of class "mongo.cursor" which is used to step through the matching records.
Note that an empty cursor will be returned if a database error occurred.
mongo.get.server.err()
and
mongo.get.server.err.string()
may be examined in that case.
mongo.cursor
,
mongo.cursor.next
,
mongo.cursor.value
,
mongo.find.one
,
mongo.insert
,
mongo.index.create
,
mongo.update
,
mongo.remove
,
mongo,
mongo.bson.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | mongo <- mongo.create()
if (mongo.is.connected(mongo)) {
buf <- mongo.bson.buffer.create()
mongo.bson.buffer.append(buf, "age", 18L)
query <- mongo.bson.from.buffer(buf)
# Find the first 100 records
# in collection people of database test where age == 18
cursor <- mongo.find(mongo, "test.people", query, limit=100L)
# Step though the matching records and display them
while (mongo.cursor.next(cursor))
print(mongo.cursor.value(cursor))
mongo.cursor.destroy(cursor)
# shorthand: find all records where age=32, sorted by name,
# and only return the name & address fields:
cursor <- mongo.find(mongo, "test.people", list(age=32),
list(name=1L), list(name=1L, address=1L))
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.