Databases Reference
In-Depth Information
var u = c.findOne({user: username}) || {user: username};
u.readOnly = readOnly;
u.pwd = hex_md5(username + (":mongo:" + pass));
print(tojson(u));
c.save(u);
}
We can see immediately that we give it a username , password , and that there's a
readOnly option (to create a user who can only read from the given database).
Also note that you can see the JavaScript API online . The online “documentation” is
not actually very well documented, but it is a complete reference of the functions avail-
able.
There is also quite a bit of built-in help for commands. If you can't remember the
command you want to run, you can see them all as long as you remember one: the
listCommands command! This shows you the name of each command:
> db.runCommand({listCommands : 1})
{
"commands" : {
"_isSelf" : { ... },
...
}
"ok" : 1
}
If you have the command name, you can get some built-in documentation on it from
the database by running { commandName : 1, help : 1} (even if the command wouldn't
normally have 1 after its name). This will display some basic documentation that the
database has about each command, which varies from very helpful to barely English:
> db.runCommand({collstats : 1, help : 1})
{
"help" : "help for: collStats { collStats: "blog.posts" , scale : 1 }
scale divides sizes e.g. for KB use 1024",
"lockType" : -1,
"ok" : 1
}
The shell also has tab completion, so you can get suggestions of what to type next based
on the functions, fields, and even collections that exist:
> db.c
db.cloneCollection( db.constructor db.currentOP(
db.cloneDatabase( db.copyDatabase( db.currentOp(
db.commandHelp( db.createCollection(
> db.copyDatabase()
As of this writing, shell completion only works on *NIX systems.
 
Search WWH ::




Custom Search