{ "title": "hello world", "comments": [ {"id": 1, "text": "text 1"}, {"id": 2, "text": "text 2"}, {"id": 3, "text": "text 3"}, ... ], "author": "", "views": 1000, }
假设我现在知道某个 comment 的 id=2
,想删除 comments 中 id=2
的字典,也就是 {"id": 2, "text": "text 2"}
这条数据,应该怎样写呢?
如果是更新 id=2
的 text
的内容,又该如何写呢?
This can use mongodb’s array locator, details:
http://www.co-ding.com/?p=274
You can delete it from the mongodb command line like this (pymongo basically has the same format, not tested):
Updated, it seems that it is not so straightforward to write, so let’s go through it with for. .
//Or delete it first and then add it? This order may not meet the requirements. .