LokiJS icon indicating copy to clipboard operation
LokiJS copied to clipboard

Update function is necessary when obj get from LokiJs reference

Open dungvu-equix opened this issue 11 years ago • 2 comments

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,

dungvu-equix avatar Jun 29 '15 02:06 dungvu-equix

Quote from documentation:

When you call update on an object though you force a resync of the indexes of the collection

alex-golubtsov avatar Jun 29 '15 09:06 alex-golubtsov

@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.

techfort avatar Jun 29 '15 09:06 techfort