Connecting to a Database
The default host is localhost, and the default port is 27017.
Connecting to MongoDB database server at localhost port 27017:$connection = new Mongo();
Connecting to a remote host with optional custom port:$connection = new Mongo( “190.50.0.80:66001” );

Selecting a Database
MongoDB will create a new database if you try to select a database that doesn’t. Open connection to MongoDB server:$db = $connection->selectDB(‘workout’);
or$db = $connection->workout;

Asynchronous update does not return a value after insert a record.$user_collection->insert($user);

Synchronously update hold execution until it has finished inserting. The application must wait for the database.$user_collection->insert($user, array(‘safe’ => true));
To access the primary key:$user_id = $user[‘_id’];

Save a Document
An _id value is specified and exists.$user_collection->save($user);

Primary Keys and ObjectIds

MongoDB will automatically create a primary key (ObjectIds) for each document.
$user_id->getTimestamp();