我真的很苦惱,所以我希望有人可以幫助我理解爲什麼我得到這種行爲。Nedb更新添加新記錄,而不是更新現有的一個
我在它與以下記錄的文件
{"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"}
任何想法,爲什麼我的記錄與新值複製,而不是剛剛更新?