我的帖子文档结构如下:
{
"_id" : ObjectId("519e8387a720784670f412b1"),
"created_at" : ISODate("2013-05-05T00:00:00Z"),
"pic_url" : "",
"post" : "Just a test",
"user_id" : "519c7565c07cbb080e000000",
"visibility" : "public",
"comments" : [{
"_id" : ObjectId("545y7565c07cbb080e00054"),
"user_id" : ObjectId("519c7565c07cbb080e000000"),
"comment" : "dfgds",
"created_at" : ISODate("1970-01-01T00:33:33Z"),
"likes" : [{
"_id" : 1,
"user_id" : "519c7565c07cbb080e000000",
"date_liked" : ISODate("2013-05-05T00:00:00Z")
}]
}, {
"_id" : ObjectId("545y7565c07cbb080e00045"),
"user_id" : ObjectId("519c7565c07cbb080e000000"),
"comment" : "u guy..",
"created_at" : ISODate("1970-01-01T00:33:33Z"),
"likes" : [{
"_id" : 1,
"user_id" : "519c7565c07cbb080e000000",
"date_liked" : ISODate("2013-05-05T00:00:00Z")
}]
}]
}
所以我想在评论中删除一个(最后一条评论 - 你们......)。我怎样才能做到这一点? 我正在使用此查询。但它不起作用:
$collection->update(
array(
'_id' => new MongoId("519e8387a720784670f412b1"),
'comments._id' => new MongoId("545y7565c07cbb080e00045")
),
array(
'$pull' => array(
'comments.likes' => array('user_id' => $user_id)
)
)
);
我收到以下错误:
array(5) {
["updatedExisting"]=>
bool(true)
["n"]=>
int(1)
["connectionId"]=>
int(5)
["err"]=>
NULL
["ok"]=>
float(1)
}
有人请帮忙!已经坚持了很长一段时间......