javascriptlokijs

Lokijs remove item by value


I have this small db i have created in loki js

var db = new loki('loki.json');
var children = db.addCollection('children');

I have added some items and now i am trying to remove an item by the value. I am storing my values like this

var date = new Date(); 
var timestamp = date.getTime(); 
children.insert({name:pn,ts:timestamp});

and removing like this

var results = children.find();
console.log('before removal',results);
children.chain().find({'name':field_val}).remove();
console.log('after removal',results);

This is the result screenshot

enter image description here

My removal code does not work since it does not remove all items and does not remove in the correct order.

How can i remove an item by value?.


Solution

  • i think it should be children.chain().find({'name':field_val}).remove();