好的,这个问题让我发疯了,我认为 _id 应该是 ObjectID,而当我尝试使用 _id 更新它时它第一次插入它时它会正确执行它不起作用。
这是我的代码
//Save Data
function savedata($data){
$collection = $this->db->retail_logs;
$this->data = $data;
if($this->data['_id'] == NULL || $this->data['_id'] == "")
{
$this->data['_id'] = new MongoId();
}
else
{
$this->data['_id'] = ObjectID($this->data['_id']);
}
try {
$collection->update(
array("_id"=>$this->data['_id']),
$this->data, // new lead document to insert
array("upsert" => true, "safe" => true)
);
print $this->data['_id'];
} catch (Exception $e) {
print "we are not able to update";
}
}
我试图做followinf
if($this->data['_id'] == NULL || $this->data['_id'] == "")
{
$this->data['_id'] = new MongoId();
}
else
{
$this->data['_id'] = ObjectID($this->data['_id']);
}
但这似乎无济于事。
发生的事情是它第一次正确插入 ObjectID(idnumber) 然后当它进行更新时删除 ObjectID() 并插入一个与以前相同的 idnumber 的新潜在客户
所以它看起来像“IDNUMBER”