Description Usage Arguments Value See Also Examples
Count the number of records in a collection that match a query See http://www.mongodb.org/display/DOCS/Indexes.
1 | mongo.count(mongo, ns, query = mongo.bson.empty())
|
mongo |
(mongo) A mongo connection object. |
ns |
(string) The namespace of the collection in which to add count records. |
query |
mongo.bson The criteria with which to match records that are to be counted. The default of mongo.bson.empty() matches all records in the collection. Alternately, Alternately, |
(double) The number of matching records.
mongo.find
,
mongo.find.one
,
mongo.insert
,
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 21 22 23 24 25 26 27 28 29 30 31 32 | mongo <- mongo.create()
if (mongo.is.connected(mongo)) {
# Count the number of records in collection people of database test
people.count <- mongo.count(mongo, "test.people")
print("total people")
print(people.count)
buf <- mongo.bson.buffer.create()
mongo.bson.buffer.append(buf, "age", 21L)
query <- mongo.bson.from.buffer(buf)
# Count the number of records in collection people of database test
# where age == 21
just.legal.count <- mongo.count(mongo, "test.people", query)
print("people of age 21")
print(just.legal.count)
buf <- mongo.bson.buffer.create()
mongo.bson.buffer.start.object(buf, "age")
mongo.bson.buffer.append(buf, "$gte", 21L)
mongo.bson.buffer.finish.object(buf)
query <- mongo.bson.from.buffer(buf)
# Count the number of records in collection people of database test
# where age >= 21
total.legal.count <- mongo.count(mongo, "test.people", query)
print("people of age 21 or greater")
print(total.legal.count)
# shorthand using a list:
ford.count <- mongo.count(mongo, "test.cars", list(make="Ford"))
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.