Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

find({}) scrambles data file #666

Open
alexHunter854 opened this issue Jan 10, 2021 · 1 comment
Open

find({}) scrambles data file #666

alexHunter854 opened this issue Jan 10, 2021 · 1 comment

Comments

@alexHunter854
Copy link

each time I do database.find({}) it scrambles up the datafile e.g.:

if we start with (data file name).db equaling to:

{"timestamp":0,"_id":"WCFTwmVybm6r0o9G"}
{"timestamp":1,"_id":"5E8twe59ulwJ9pck"}
{"timestamp":2,"_id":"s0eUV0Nt8JjOsHKO"}

and we make a find({}) request we end up with a (data file name).db that may equal to:

{"timestamp":2,"_id":"s0eUV0Nt8JjOsHKO"}
{"timestamp":0,"_id":"WCFTwmVybm6r0o9G"}
{"timestamp":1,"_id":"5E8twe59ulwJ9pck"}

given the small sample size of three it may come out as sorted but if the database is hundreds of entries long you will never get it in the right order this seems too puzzling to be intended behavior, I know you can fix this with sort() but let's say I can't use sort() for our purposes.

I really hope that this is not the intended behavior because it feels really really janky.

@jampy
Copy link

jampy commented Jan 11, 2021

I guess that is per design, see auto-compacting: https://github.com/louischatriot/nedb#persistence

You might not expect the data to be persisted in any specific order. If you need a specific sorting, let the database sort it during find().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants