2012-03-25 3 views
14

db.users.remove ({_ id : "4f6f244f6f35438788aa138f"}) 을 사용하여 문서를 삭제하려고했지만이 명령은 아무 것도 삭제하지 않습니다._id를 기준으로 문서를 제거하는 방법은 무엇입니까?

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

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

답변

22

당신은 당신이 ObjectId가 아닌 문자열을 통과해야

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

을 시도했다.

+0

네, 효과가 있습니다. 덕분에 –

+0

당신은 환영합니다 - 나는 그 시간도 낭비했다 :) – Blacksad

관련 문제