ichikaway/cakephp-mongodb — Issue #41: SubDocument Set Operator
Author: ratbie
Created: 2011-12-04 09:26:28+00:00
State: open

I'm not sure this is error or not.

I tried to run sample/subdocuments.

1st) I insert data.

{
"_id": ObjectId("4edb39e3b33109e408000001"),
"title": "aa",
"body": "bb",
"subdoc": {
"0": {
"name": "cc",
"age": "11"
},
"1": {
"name": "dd",
"age": "ff"
}
},
"modified": ISODate("2011-12-04T09: 14: 11.0Z"),
"created": ISODate("2011-12-04T09: 14: 11.0Z")
}

2nd) I modified subdocumentscontroller -> function edit . Just remove the subdoc -> 0 -> name from updating(refer below)

unset($this->request->data['Subdocument']['subdoc'][0]['name']);
if ($this->Subdocument->save($this->data)) {

3rd) I edit and click submit and able to get the query update

db.subdocuments.update( {"_id":ObjectId ("4edb39e3b33109e408000001")}, {"$set":{"title":"aa","body":"bb","subdoc":[{"age":"11"},{"name":"dd","age":"ff"}],"modified":"MongoDate(0.00000000 1322990285)"}}, {"multiple":false} )

The document become

"_id": ObjectId("4edb39e3b33109e408000001"),
"body": "bb",
"created": ISODate("2011-12-04T09: 14: 11.0Z"),
"modified": ISODate("2011-12-04T09: 18: 05.0Z"),
"subdoc": {
"0": {
"age": "11"
},
"1": {
"name": "dd",
"age": "ff"
}
},
"title": "aa"

From the update query , the update operator is "$set "and should not affected the subdoc->0->name as it just update the fields where we define.
My question is why the subdoc->0->name missing as the operator set is there?