2012-03-25 25 views
14

Bir belgeyi db.users.remove ({_ id: "4f6f244f6f35438788aa138f"}) kullanarak silmeye çalıştım ancak bu komut hiçbir şeyi silmez.Belge _id temelinde nasıl kaldırılır?

> // myobject is some document that is in our db.things collection 
> db.things.remove({_id: myobject._id}); 

'Nesnem nedir?' mongodb belgelerinde.

> 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"}) 

cevap

22

Eğer Bir objectId değil, bir dize geçmelidir

db.things.remove({_id: ObjectId("4f6f244f6f35438788aa138f")}); 

deneyin yaptı.

+0

evet çalışıyor. teşekkürler –

+0

hoş geldiniz - Ben de bunun için biraz zaman harcadım :) – Blacksad

İlgili konular