Database Reference
In-Depth Information
>use blog
switched to db blog
>db.addUser("shadycharacter","shadypassword", true)
Deleting a User
To remove a user from a database, simply use the normal remove() function for a collection. The following example
removes the user just added; note that you have to authenticate against the admin database before you can remove
the user:
$mongo
>use admin
switched to db admin
> db.auth("admin","pass")
1
>use blog
switched to db blog
>db.removeUser("shadycharacter")
Using Authenticated Connections in a PHP Application
In Chapter 4, you saw how to create a connection with PHP to a MongoDB server. Once you have enabled
authentication on your server, PHP applications will also have to supply credentials before they can execute
commands against the server. The following simple example shows how to open an authenticated connection
to a database:
<?php
// Establish the database connection
$connection = new Mongo();
$db = $connection->selectDB(“admin”);
$result = $db->authenticate(“admin”, “pass”);
if(!$result['ok']){
// Your Error handling here
die(“Authentication Error: {$result['errmsg']}”);
}
// Your code here
// Close the database connection
$connection->close();
?>
Managing Servers
As an administrator, you must ensure the smooth and reliable running of your MongoDB servers.
 
Search WWH ::




Custom Search