javascript - nedb method update and delete creates a new entry instead updating existing one -


i'm using nedb , i'm trying update existing record matching it's id, , changing title property. happens new record gets created, , old 1 still there. i've tried several combinations, , tried googling it, search results 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 crazier when performing delete, new record gets added again, time record has weird property: {"$$deleted":true,"_id":"wfzamyrx51uzxbs7"}

this code i'm using:

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

in nedb docs says followings :

localstorage has size constraints, it's idea set recurring compaction every 2-5 minutes save on space if client app needs lot of updates , deletes. see database compaction more details on append-only format used nedb.

 

compacting database

under hood, nedb's persistence uses append-only format, meaning updates , deletes result in lines added @ end of datafile. reason disk space cheap , appends faster rewrites since don't seek. database automatically compacted (i.e. put in one-line-per-document format) everytime application restarts.

you can manually call compaction function yourdatabase.persistence.compactdatafile takes no argument. queues compaction of datafile in executor, executed sequentially after pending operations.

you can set automatic compaction @ regular intervals yourdatabase.persistence.setautocompactioninterval(interval), interval in milliseconds (a minimum of 5s enforced), , stop automatic compaction yourdatabase.persistence.stopautocompaction().

keep in mind compaction takes bit of time (not much: 130ms 50k records on slow machine) , no other operation can happen when does, projects don't need use it.

i didn't use seems , uses localstorage , has append-only format update , delete methods.

when investigated source codes, in search in persistence.tests wanted sure checking $$delete key have mentioned `if doc contains $$deleted: true, means need remove data``.

so, in opinion can try compacting db manually, or in question; second way can useful.


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -