我真的很挣扎,所以我希望有人能帮助我理解为什么我会出现这种行为。
我有一个包含以下记录的文件
{"Id":"","documentPath":"mission.pdf","dName":"BIOLOGY TEST 1110","dCourseNumber":"1110","dSubject":"BIOL","dTerm":"201690","dTitle":"BIOLOGY TEST 1110","student":"491502","timestamp":1486152313972,"assessed":true,"errorCmt":"","uploadDate":"2/3/2017 14:5","_id":"QwKHQ8sRQdivRJDp"}
{"Id":"","documentPath":"university.pdf","dName":"BIOLOGY TEST 1111","dCourseNumber":"1111","dSubject":"BIOL","dTerm":"201690","dTitle":"BIOLOGY TEST 1111","student":"491502","timestamp":1486151521825,"assessed":false,"errorCmt":"","uploadDate":"2/3/2017 13:52","_id":"mh0pdGERB6fZU4s3"}
在我的 testdb.js 文件中,我有:
var Datastore = require('nedb');
var db = new Datastore({filename: './db.db', autoload: true});
db.update({ _id: "QwKHQ8sRQdivRJDp"}, { $set: { assessed: true} }, {}, function (err, numReplaced) {
console.log("replaced---->" + numReplaced);
});
db.find({}).exec(function (err, docs) {console.log(docs);});
我最后执行的查找表明我已经更新了一条记录并打印出记录,它们看起来与我期望的一样。如果我打开 db.db,我现在会看到:
{"Id":"","documentPath":"mission.pdf","dName":"BIOLOGY TEST 1110","dCourseNumber":"1110","dSubject":"BIOL","dTerm":"201690","dTitle":"BIOLOGY TEST 1110","student":"491502","timestamp":1486152313972,"assessed":true,"errorCmt":"","uploadDate":"2/3/2017 14:5","_id":"QwKHQ8sRQdivRJDp"}
{"Id":"","documentPath":"university.pdf","dName":"BIOLOGY TEST 1111","dCourseNumber":"1111","dSubject":"BIOL","dTerm":"201690","dTitle":"BIOLOGY TEST 1111","student":"491502","timestamp":1486151521825,"assessed":false,"errorCmt":"","uploadDate":"2/3/2017 13:52","_id":"mh0pdGERB6fZU4s3"}
{"Id":"","documentPath":"mission.pdf","dName":"BIOLOGY TEST 1110","dCourseNumber":"1110","dSubject":"BIOL","dTerm":"201690","dTitle":"BIOLOGY TEST 1110","student":"491502","timestamp":1486152313972,"assessed":true,"errorCmt":"","uploadDate":"2/3/2017 14:5","_id":"QwKHQ8sRQdivRJDp"}
知道为什么我的记录与新值重复,而不仅仅是更新吗?