Professional Documents
Culture Documents
Richard M Kreuter
10gen Inc.
richard@10gen.com
Interactive development/prototyping.
Test scripting (cf. MongoDBs own regression framework).
Administrative operations, lightweight scripting.
Learning MongoDB (and teaching it, too).
$ mongo
MongoDB shell version: 1.6.4
connecting to: test
> db.people.save({name:"Washington", no: 1});
> db.people.save({name:"Adams", no: 2});
> db.people.save({name:"Jefferson", no: 3});
> for (i=0; i<1024; i++) db.numbers.save({ num: i });
Shell helpers
The shell has some built-in helpers that resemble the MySQL
shells.
// Change database to "foo"
use foo
// List the collections in "foo"
show collections
Note that these helpers arent strictly JavaScript; theyre sort of
preprocessors available only when the shell is run interactively.
There are proper JavaScript methods for doing these things
programmatically (e.g., db=db.getSisterDB("foo")).
Command-line editing
Getting help
> db.numbers.find()
{ "_id" : ObjectId("4cf91b32e3f85d1561593dfc"), "num" : 0 }
...
has more
> it
{ "_id" : ObjectId("4cf91b32e3f85d1561593e10"), "num" : 20
...
has more
A nifty function
Gotchas