A
A
Alexander Wolf2015-09-25 12:46:52
JavaScript
Alexander Wolf, 2015-09-25 12:46:52

How to correctly store record order in mongo?

Hey! I have a collection of records that can be moved between themselves using dran-n-drop.
Each entry has an index field. However, there are difficulties with constant surveillance of them. Somewhere they removed an element from the middle - recalculation, somewhere they added it to the center - also recalculation. Etc.
I would like something simpler. Or maybe there is a solution?
PS: I am using meteor & sortable package.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lega, 2015-10-04
@lega

It depends on how the data is used, you can do this:
1) do not change the index of the documents
2) when deleting the document, do not touch the rest of the documents
3) When inserting between 3 and 4, make the index 3.5, and between 3.5 and 4 -> 3.75 etc. The main thing is that the correct sorting of documents would be correct.
4) Calculate the index on the fly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question