Description Usage Arguments Details Value See Also Examples
Issue a command to a MongoDB server and return the response from the server.
1 | mongo.command(mongo, db, command)
|
mongo |
(mongo) A mongo connection object. |
db |
(string) The name of the database upon which to perform the command. |
command |
(mongo.bson) An object describing the command. Alternately, Alternately, |
This function supports any of the MongoDB database commands by allowing you to specify the command object completely yourself.
See http://www.mongodb.org/display/DOCS/List+of+Database+Commands.
NULL if the command failed. mongo.get.err()
may be
MONGO_COMMAND_FAILED.
(mongo.bson) The server's response if successful.
mongo.get.err
,
mongo.simple.command
,
mongo.rename
,
mongo.count
,
mongo.drop.database
,
mongo.drop
,
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 | mongo <- mongo.create()
if (mongo.is.connected(mongo)) {
# alternate method of renaming a collection
buf <- mongo.bson.buffer.create()
mongo.bson.buffer.append(buf, "renameCollection", "test.people")
mongo.bson.buffer.append(buf, "to", "test.humans")
command <- mongo.bson.from.buffer(buf)
mongo.command(mongo, "admin", command)
# use list notation to rename the collection back
mongo.command(mongo, "admin",
list(renameCollection="test.humans", to="test.people"))
# Alternate method of counting people
buf <- mongo.bson.buffer.create()
mongo.bson.buffer.append(buf, "count", "people")
mongo.bson.buffer.append(buf, "query", mongo.bson.empty())
command <- mongo.bson.from.buffer(buf)
result = mongo.command(mongo, "test", command)
if (!is.null(result)) {
iter = mongo.bson.find(result, "n")
print(mongo.bson.iterator.value(iter))
}
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.