gpt4 book ai didi

node.js - Nedb 更新是添加新记录而不是更新现有记录

转载 作者:太空宇宙 更新时间:2023-11-04 00:28:04 25 4
gpt4 key购买 nike

我真的很挣扎,所以我希望有人能帮助我理解为什么我会出现这种行为。

我有一个文件,其中包含以下记录

{"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"}

知道为什么我的记录会重复新值而不只是更新吗?

最佳答案

NeBD 使用仅附加模式来提高性能,如果您想真正“更新”和“删除”,您应该压缩数据库,请参阅此相关问题我相信这个解释让您了解更多有关 Nedb - nedb method update and delete creates a new entry instead updating existing one

关于node.js - Nedb 更新是添加新记录而不是更新现有记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42032796/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com