Are Lokijs ID's Unique?

1.8k Views Asked by At

Are lokijs id's ($loki) unique?

if I have 2 documents from one collection with $loki:1 and $loki:2 as id's, and I delete $loki:1, the next one I create should it be $loki:3 ???

1

There are 1 best solutions below

1
On BEST ANSWER

That's correct. Collections keep track of the last ID that was created and assign the a lastId + 1 value to the $loki property of the next object you insert in a collection. You can check the value of the last id by checking collection.maxId and deduce the next id by simply adding 1 to that.