runCommand() – Run one or more specified database commands
Helps to run specified database commands commands.
Syntax diagram
Command parameters
- command
- A database command, specified either in document form or as a string.
Examples
The following example shows the command syntax for converting the collection,
mycoll
, to a capped collection:db.runCommand({
“convertToCapped” : “mycoll”,
size : 100000
})
The following example shows the command syntax for inserting documents into the collection,
books
:db.runCommand({
“insert” : “books”,
“documents” : [
{ “isbn” : “123-456-789”, “author” : “Verne, Jules”,
“title” : “Journey to the Center of the Earth”
}
]
})
The following example shows the command syntax for deleting documents from the collection,
mycoll
:db.runCommand({
“delete” : “mycoll”,
“deletes” : {
“query” : { “points” : { $gt : 2500 } },
“limit” : 4
}
})
The following example shows the command syntax for updating documents in the collection,
mycoll
:db.runCommand({
“update” : “mycoll”,
“updates” : {
“query” : { “points” : { $gt : 2500 } },
“updateSpec : { $set : { “assignment” : 5 } },
“multi” : true,
“upsert” : false
}
})
The following example shows the command syntax for finding the documents
points
and assignment
in the collection,
mycoll
:db.runCommand({
“find” : “mycoll”,
“query” : {
“points” : { $gt : 2500 },
“assignment” : { $lt : 50 }
},
“limit” : 3,
“skip” : 1
})
db.runCommand({
“find” : “mycoll”,
})
The following example shows the command syntax for finding and updating the document
points
in the collection, mycoll
:db.runCommand({
“findAndModify” : “mycoll”,
“query” : { “points” : 1 },
“updateSpec” : { $set : { “status” : “C” } },
“returnNew” : true
})
db.runCommand({
“findAndModify” : “mycoll”,
“query” : { “points” : 0 },
“remove” : true
})
The following example shows the command syntax for finding the number of documents in the
collection,
mycoll
:db.runCommand({
“count” : “mycoll”
})
db.runCommand({
“count” : “mycoll”
“query” : { “points” : { $gt : 17 } }
})