feathersjs-ecosystem / feathers-nedb

A service using NeDB, an embedded datastore for Node.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Patch duplicates records

0xPaladin opened this issue · comments

Good day,

I am developing and I an trying to use patch internally. This is from a separate js file:
src/cpx/peers.js

Top:
const app = require('../app');
const peerService = app.service('peers');

An example of my patch:
peerService.patch(peer._id,peerdata,{});

Anytime I call a patch function, a new record is created in the peers.db. I was expected the data to be merged and individual fields to be updated.

An example of a peer in the db:
{"ip":"104.207.140.133", "port":3030,"active":"false","lastContact":1470325684133,"connected":"false","_id":"Cy0cPJAHS6OgjDaL"}

with the patch I'm trying to update only some things:
peerdata = {
active: "true",
"lastContact":new Date().getTime()
}

Since I ping servers routinely - I have numerous records, all with the same _id, but with incremented times.

This is the same issue as feathersjs/feathers#379 and just how NeDB seems to store its entries. As long as peerService.find() does return the correct data with no duplicates I wouldn't worry about how the storage file looks like.

Thank you! Sorry to duplicate...

I did some digging this morning and I found this on nedb:
Persistence

Under the hood, NeDB's persistence uses an append-only format, meaning that all updates and deletes actually result in lines added at the end of the datafile, for performance reasons. The database is automatically compacted (i.e. put back in the one-line-per-document format) every time you load each database within your application.

I was just about to close this out with this information.