public function insert($col, $doc = [], $cb = null, $params = [])
{
if (mb_orig_strpos($col, '.') === false) {
$col = $this->dbname . '.' . $col;
}
if (!isset($doc['_id'])) {
$doc['_id'] = new \MongoId();
}
if ($this->safeMode) {
static::safeModeEnc($doc);
}
try {
$this->request(self::OP_INSERT, "" . $col . "" . bson_encode($doc), false, null, function ($conn, $reqId = null) use($cb, $col, $params) {
if ($cb !== null) {
$this->lastError($col, $cb, $params, $conn);
}
});
return $doc['_id'];
} catch (\MongoException $e) {
Daemon::log('MongoClient exception: ' . $e->getMessage() . ': ' . $e->getTraceAsString());
if ($cb !== null) {
if ($cb !== null) {
$cb(['$err' => $e->getMessage(), '$doc' => $doc]);
}
}
}
}