In console mode Mongo shell commands can be executed. The inputs are not formatted by the application or modified, but forwarded unchanged to the Mongo shell.
Tipp |
---|
Here you will find a documentation of the Mongo shell commands: http://docs.mongodb.org/manual/core/crud-introduction/ |
Codeblock |
---|
theme | Emacs |
---|
language | js |
---|
linenumbers | true |
---|
|
// Returns all documents
db.zipcode.find();
// Returns all cities name and sorted by them
db.zipcode.find({}, {city: 1}).sort({city: 1})
// Create a new zipcode document
db.zipcode.insert({_id: '99999', city: 'LEIPZIG', pop: 520838, state: 'SN'})
// Analyze the find-query
db.zipcode.find().explain()
// Show the statistics of the collection
db.zipcode.stats(); |
Warnung |
---|
In console mode, there is no pager. Therefore, all records are loaded for each query. Because this can be a very large amount of data in circumstances, the result is limited to 100 documents. It is recommended to use the functions skip () and limit (). |
Info |
---|
Using a single command, the semicolon at the end is optional. |
You can enter multiple commands. These have to be included in a function and the result must be returned with the return statement.
Codeblock |
---|
|
function () {
var stats = db.zipcode.stats();
var index = db.zipcode.getIndexes();
return {
stats: stats,
indexInformation: index
};
} |
Hinweis |
---|
The console mode only works if the server instance of Mongo has enabled server-side JavaScript. This is enabled by default. |