Update function is necessary when obj get from LokiJs reference
My case is with LokiJs version 1.3.4: var accountInfo = _db.addCollection('AccountInfo', { indices: ['AccountId'] }); .... var item = accountInfo.findOne({ 'AccountId': 123}); //AccName='Account123' item.AccName = 'test'; //set new dummy data and without using function Update like: accountInfo.update(item). The data in Loki still changed by re-load data again: var itemClone = accountInfo.findOne({ 'AccountId': 123 }); return item.AccName == 'test'); ==> return true
And we wonder why we must call function update for the change? Is there any way to get a clone value only (for all function get data: find, findOne, get....).
Thanks for support,
Quote from documentation:
When you call update on an object though you force a resync of the indexes of the collection
@alex21 thanks for clarifying. I will add that you can obtain the desired behaviour by using the clone property when creating the collection, this will return object copies instead of the object reference.