mongodb 'document' variable define in PHP mongodb 'document' variable define in PHP mongodb mongodb

mongodb 'document' variable define in PHP


Finally no way for my question. I searched in many way. So, We can create the document variable when using another run time query (using $set or else). Thanks.


The MongoDB PHP driver supports sending in empty objects (it has no validation on it's end to make sure you send something of value) to be saved but detecting that this method of saving objects would be useless without knowing the _id of the object you have just saved you can do:

$a = array();$db->user->insert($a);var_dump($a['_id']);

Since if passed a variable, the insert function for MongoDB will modify (by reference) the original variable and add the _id field to it.

You cannot save a "empty" object however (an object without the immutable _id) to a normal collection. This of course differs for things like capped collections.