而不是更新现有条目

而不是更新现有条目

本文介绍了nedb方法更新和删除会创建一个新条目,而不是更新现有条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用,我正在尝试通过匹配<$ n来更新现有记录c $ c> ID ,并更改标题属性。
结果是创建了一条新记录,而旧记录仍在那里。
我尝试了几种组合,并尝试使用谷歌搜索,但搜索结果很少。



  var Datastore = require( 'nedb'); var db = {files:new Datastore({filename:'。/ db / files.db',autoload:true})}; db.files.update({_ id:id},{$ set: {title:title}},{},callback);  



执行删除时更加疯狂,再次添加新记录,但这次记录有一个奇怪的属性:
{$$ deleted:true,_ id:WFZaMYRx51UzxBs7 }



这是我正在使用的代码:



  db.files.remove({_ id:id},callback);  

解决方案

在nedb文档中,它说如下:

 

我没有使用它,但似乎,它使用localStorage,它只有附加格式的更新和删除方法。



调查其源代码时, in se se在persistence.tests中他们想确保检查 $$ delete 密钥,他们也提到了`如果一个doc包含$$删除:true,那就意味着我们需要从数据``中删除它。



所以,在我看来,你可以尝试手动压缩数据库,或者在你的问题中;第二种方式很有用。


I'm using nedb and I'm trying to update an existing record by matching it's ID, and changing a title property.What happens is that a new record gets created, and the old one is still there.I've tried several combinations, and tried googling for it, but the search results are scarce.

var Datastore = require('nedb');
var db = {
    files: new Datastore({ filename: './db/files.db', autoload: true })
};

db.files.update(
  {_id: id},
  {$set: {title: title}},
  {},
  callback
);

What's even crazier when performing a delete, a new record gets added again, but this time the record has a weird property:{"$$deleted":true,"_id":"WFZaMYRx51UzxBs7"}

This is the code that I'm using:

db.files.remove({_id: id}, callback);

解决方案

In the nedb docs it says followings :

 

I didn't use this but it seems , it uses localStorage and it has append-only format for update and delete methods.

When investigated its source codes, in that search in persistence.tests they wanted to sure checking $$delete key also they have mentioned `If a doc contains $$deleted: true, that means we need to remove it from the data``.

So, In my opinion you can try to compacting db manually, or in your question; second way can be useful.

这篇关于nedb方法更新和删除会创建一个新条目,而不是更新现有条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 06:56