2013-08-18 2 views
0

mongodb 데이터베이스의 문서와 실패한 비참한 문서를 업데이트하려고합니다. 여기문서 업데이트

https://github.com/mongodb/node-mongodb-native 내 코드입니다 :

내가 Node.js를이 드라이버를 사용하고 여기에

db.collection('test').update({ _id: '5210f6bc75c7c33408000001' }, {$set: { title: "new title"}, {w:1}, function(err) { 
     if (err) console.warn(err.message); 
     else console.log('successfully updated'); 
    }); 

내 데이터베이스입니다 : 나는 successfully updated 메시지를 작성

> db.test.find() 
{ "type" : "new", "title" : "my title", "desc" : [ "desc 1" ], "_id" : ObjectId(" 
5210f6bc75c7c33408000001") } 
> 

하지만, 변화는 일어나지 않았다.

내가 뭘 잘못하고 있니?

답변

0

당신은 당신의 ID가 _id 필드가 실제로 유형 ObjectId가의 객체가 아닌 문자열 인 ObjectId가

db.collection('test').update({ _id: ObjectId('5210f6bc75c7c33408000001') }, {$set: { title: "new title"}, {w:1}, function(err) { 
     if (err) console.warn(err.message); 
     else console.log('successfully updated'); 
    }); 

로 속성을 설정해야합니다. 성공한 이유는 오류가 없기 때문에 해당 문자열에 _id가있는 객체를 찾지 못하기 때문입니다.