我尝试使用db.users.remove({_ id:"4f6f244f6f35438788aa138f"})删除文档,但此命令不会删除任何内容.
> // myobject is some document that is in our db.things collection
> db.things.remove({_id: myobject._id});
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚'myobject是什么?' 在mongodb文档中.
> db.users.find()
{ "_id" : ObjectId("4f6cd2cb7156522f4f45b26d"), "name" : "james", "age" : 23,
"hobbies" : [ "cycling", "painting" ] }
{ "_id" : ObjectId("4f6cd3017156522f4f45b26e"), "name" : "john", "age" : 30 }
{ "_id" : ObjectId("4f6f244f6f35438788aa138f"), "name" : "john" }
{ "_id" : ObjectId("4f6f24556f35438788aa1390"), "name" : "john" }
> db.users.remove({_id: "4f6f244f6f35438788aa138f"})
Run Code Online (Sandbox Code Playgroud)
Bla*_*sad 26
你试过了吗
db.things.remove({_id: ObjectId("4f6f244f6f35438788aa138f")});
Run Code Online (Sandbox Code Playgroud)
您必须传递ObjectId,而不是字符串.
| 归档时间: |
|
| 查看次数: |
13009 次 |
| 最近记录: |