私は少し問題があります、あなたが私を助けることを願っています。 私はMongoDBの中で次の配列構造を有する:MongoDBの内部配列にデータを挿入
{
"_id":ObjectId("4e43cf96e7c7914b87d2e0ff"),
"list" :[
{
"id" : ObjectId("4e43cf96e62883ee06000002"),
"user_name" : "login",
"comments" : [ ] //insert here new data
},
{
"id" : ObjectId("4e43cf96e62883ee06000003"),
"user_name" : "login",
"comments" : [ ]
}
]
}
そして、私は「list.id」でのコメントに新しいデータを挿入します。
$post_id = "4e43cf96e62883ee06000002";
$this->connection->user->feed->update(
array ('list.id' => new MongoId($post_id)),
array ('$push' => array ('list'=>array('comments'=>$data)))
)
しかし、そのコードは、構造体の新しいフィールドを作成しますが、 'コメント' 欄にデータを追加していない:しかし、私はそのようにしてみてください
{
"_id":ObjectId("4e43cf96e7c7914b87d2e0ff"),
"list" :[
{
"id" : ObjectId("4e43cf96e62883ee06000002"),
"user_name" : "login",
"comments" : [ ] //insert here new data
},
{
"id" : ObjectId("4e43cf96e62883ee06000003"),
"user_name" : "login",
"comments" : [ ]
},
{
"comments" : { //added new field
//there is my data
}
]
}
をも私が試した:
$this->connection->user->feed->update(
array ('list.id' => new MongoId($post_id)),
array ('$push' => array ('list.comments'=>$data))
);
しかし何も。
yea、あなたは正しい;)たくさんありがとう!そして、 "$。"という文字が "リスト。$コメント"の中で何を意味するのかを教えてください。または私に参照を与える?ありがとう! –
[[docへのリンク](http://www.mongodb.org/display/DOCS/Updating#Updating-The%24positionaloperator) – Igorekk