LokiJS icon indicating copy to clipboard operation
LokiJS copied to clipboard

collection.clear() on a collection with unique index does not allow you to re-add any of the previously used data

Open JamesWilsonProjects opened this issue 9 years ago • 11 comments

I have a collection created like so: db.addCollection("gData", {unique: ['RIN']}); This data is loaded from a file.

In some use cases of my application I want to allow to user to re-read the file, so I use:

let gData = db.getCollection("gData");
gData.clear();

When I try to re-read the file, I get duplicate key errors. I've verified that the collection is indeed empty after calling clear().

The only way I can get it to work correctly is if I completely remove the collection and re-add it.

JamesWilsonProjects avatar Dec 27 '16 23:12 JamesWilsonProjects

should be fixed now, I think we discussed this in #462 but fix never got added

obeliskos avatar Dec 28 '16 15:12 obeliskos

i believe this was fixed so closing.. reopen if still issue

obeliskos avatar Jan 31 '17 01:01 obeliskos

Unfortunately I can see the same issue on the latest version [1.4.2]. Please reopen this issue.

lechu1985 avatar Feb 02 '17 15:02 lechu1985

No need to reopen the issue, it's fixed but only on the master. It has been fixed after the 1.4.2 release.

Kanaye avatar Feb 02 '17 16:02 Kanaye

Thanks, yes I just verified here that the latest master branch works as expected.

I thought this was done before official 1.4.2 release sorry, once we test out another new option we will try to get techfort to update 'releases' and npm to include this.

obeliskos avatar Feb 03 '17 01:02 obeliskos

Will publish 1.4.3 asap

On Fri 3 Feb 2017, 01:07 obeliskos, [email protected] wrote:

Thanks, yes I just verified here https://rawgit.com/techfort/LokiJS/master/examples/sandbox/LokiSandbox.htm#rawgist=https://gist.githubusercontent.com/obeliskos/4cb05015e94286f63f510c2716b9ca1d/raw/acaa87aea6b22b26fc900b1f291489cf4aaef9b0/collectionClearWithUniqueIdx that the latest master branch works as expected.

I thought this was done before official 1.4.2 release sorry, once we test out another new option we will try to get techfort to update 'releases' and npm to include this.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/techfort/LokiJS/issues/522#issuecomment-277135829, or mute the thread https://github.com/notifications/unsubscribe-auth/AD8FfZcNAt4r06DIuPSmwobi6rS6egU1ks5rYn25gaJpZM4LWkux .

techfort avatar Feb 03 '17 08:02 techfort

Great. Thanks a lot guys.

03.02.2017 9:03 AM "techfort" [email protected] napisał(a):

Will publish 1.4.3 asap

On Fri 3 Feb 2017, 01:07 obeliskos, [email protected] wrote:

Thanks, yes I just verified here <https://rawgit.com/techfort/LokiJS/master/examples/ sandbox/LokiSandbox.htm#rawgist=https://gist.githubusercontent.com/ obeliskos/4cb05015e94286f63f510c2716b9ca1d/raw/ acaa87aea6b22b26fc900b1f291489cf4aaef9b0/collectionClearWithUniqueIdx> that the latest master branch works as expected.

I thought this was done before official 1.4.2 release sorry, once we test out another new option we will try to get techfort to update 'releases' and npm to include this.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/techfort/LokiJS/issues/522#issuecomment-277135829, or mute the thread <https://github.com/notifications/unsubscribe-auth/ AD8FfZcNAt4r06DIuPSmwobi6rS6egU1ks5rYn25gaJpZM4LWkux> .

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/techfort/LokiJS/issues/522#issuecomment-277187226, or mute the thread https://github.com/notifications/unsubscribe-auth/AXGgp-nyEMnvgGBR9dCW9-9fE5W5MpxCks5rYt9RgaJpZM4LWkux .

lechu1985 avatar Feb 03 '17 13:02 lechu1985

@lechu1985 I should clarify that "asap" is as soon as @obeliskos is finished testing out another feature that will make it into 1.4.3.

techfort avatar Feb 03 '17 16:02 techfort

Thanks @techfort, i'll give throttledSaves a run through myself this weekend and if all looks good I will just make that option true by default and we can then release it.

obeliskos avatar Feb 03 '17 23:02 obeliskos

@techfort, I have tested and unit tested the throttledSaves functionality but also expanded it to more completely provide clean db saves and loads.

As of commit 1000 (wow two landmarks) this should be complete, maybe give a day or so for early adopters to test but it should be ready to go.

Fixes/features made since 1.4.2 :

  • fixed overlapping saves/loads by implementing throttling saves and loads
  • simulate async in LokiMemoryAdapter (for unit testing)
  • simplesorts on unfiltered resultsets can leverage binary indices
  • clone inserts now return obj with $loki and meta
  • collection clear now clears unique and binary indices leaving in place (by default)

obeliskos avatar Feb 06 '17 11:02 obeliskos

@obeliskos thanks a million, if you can ping me when you think this is ready for publishing i will get on it right away. Thanks a lot as usual for the great work.

techfort avatar Feb 06 '17 12:02 techfort