0
PHP로 MongoDB를 배우려고합니다. -> save ($ object)를 사용하여 새 문서를 성공적으로 저장할 수 있습니다. 내 목표는 특정 _id 가진 문서에 하위 문서를 추가하는 것입니다. 나는 "이동"으로 새 문서를 삽입 할PHP/MongoDB - _id로 문서에 하위 문서 추가
"5197f4bef045a1d710000032": {
"_id": {
"$id": "5197f4bef045a1d710000032"
},
"tag": 5487,
"serial": "1z5589ss56",
"type": "Soda Can",
"dept": "NOC",
"location": "Mitchell",
"date": 1368913086,
"moves": null
}
:
나는 문서를 가지고있다.
나는 $ set으로 한 번 할 수 있었지만, 이후 $ push는 아무 것도하지 않았다.
<?php
$m = new Mongo();
$d = $m->selectDB('peeps');
$c = $d->family;
$fields = array('tag' => 5487 , 'serial' => '1z5589ss56', 'type' => 'Soda Can', 'dept' => 'NOC', 'location' => 'Mitchell', 'date' => time());
$can = new Asset($fields);
#$c->save($can);
#Update to insert move
$c->update(array('_id' => new MongoID('5197f0cef045a1d710000032')), array('$push' => array('moves' => $can)));
$cur = $c->find();
$J = json_encode(iterator_to_array($cur));
print($J);
class Asset{
public $tag;
public $serial;
public $type;
public $dept;
public $location;
public $date;
public $moves;
public function __construct($fields){
$this->tag = $fields['tag'];
$this->serial = $fields['serial'];
$this->type = $fields['type'];
$this->dept = $fields['dept'];
$this->location = $fields['location'];
$this->date = $fields['date'];
}
}
내가 읽은 내용을 바탕으로,이 안에 중첩 된 문서를 만들어 페이지를 다시로드 할 때마다 5197f0cef045a1d710000032.moves한다.
내가 무엇을 놓치고 있는지 잘 모르겠습니다.
감사합니다, 나중에 같은 분야에 $push
를 사용할 계획이라면 당신은 간단한 값으로 설정 $를 사용하지 않아야
미첼
감사합니다. 왜 숲에있는 나무를 찾을 수 없었는지 잘 모르겠습니다. :) – xandout