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

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);


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source