<?php
/**
* Insert Record
* Parameters:
* $table _name: Table name
* $record: Record
*
* return value:
* Success: True
* Failed: false
*
/function Insert ($table _name, $record) {
$dbname = $this->curr_db_name;
try{
$this->mongo-> $dbname->insert ($record, Array (' safe ' =>true); The method to perform a secure write is return
true;
} catch (Mongocursorexception $e) {
$this->error = $e->getmessage ();
return false;
}
? >
As shown in the figure:
The parameter $record is actually a pointer reference that automatically returns the _ID key in the $record array after the insert succeeds
Array ([
0]=>array [
username]=>username570
[password]=>password200
] [
1]= > Insert before
)
Array ([
0]=>array [
username]=>username570
[password]=>password200
[_id]=>mongoid Object (
[$id]=>35jdfas8dfsafaa9869
)
]
[1]=>999
)
Note also that the returned $record ["_id"] is a Mongoid object that can be used directly as a MongoDB query condition and not converted back and forth.