이 문제를 파악할 수 없으며 터미널을 사용하여 동일한 쿼리를 실행하려고 시도했지만 성공했습니다. 동일한 쿼리가 MongoHub를 사용할 때 하나의 행을 반환하지만 레코드를 확인한 후에는 변경이 없다는 것에 유의해야합니다. 아래는 몽고 설정과 업데이트 작업입니다.addToSet을 사용한이 노드 + MongoDB 업데이트가 배열을 업데이트하지 못하는 이유는 무엇입니까?
var mongo = require('mongodb');
var Server = mongo.Server,
Db = mongo.Db,
BSON = mongo.BSONPure;
var server = new Server('localhost', 27017, {auto_reconnect: true});
db = new Db('help', server, {safe: true});
type = 'issues';
id = 2;
body = { comments: '64' };
db.collection(type, function(err, collection) {
collection.update({id:id}, {$addToSet: body}, {safe:true}, function(err, result) {
if (err) {
console.log('Error updating: ' + err);
res.send({'error':'An error has occurred'});
} else {
console.log('' + result + ' document(s) updated');
res.send(type);
}
});
});
//Mongo Collection Record
{ "_id" : ObjectId("511c000d994cde0d02adf1ba"),
"comments" : [
1,
2,
3 ],
"id" : 2,
"text" : "This is another issue test",
"title" : "Another Issue Test" }
은 어떤 도움이 크게이 부분 타입의 변수가 첫 번째 줄에 정의되어
db.collection(type, function(err, collection) {
collection.update({id:id}, {$addToSet: body}, {safe:true},
내가 볼 수없는에서 몇 가지 문제가있는 것처럼
'id = 2'인 문서가 두 개 이상있을 수 있습니까? – JohnnyHK