Closed alexgaya closed 2 years ago
Hi!
Thanks for the bug report!
I did some digging around and to me it looks like this is indeed a bug with @seald-io/nedb
or nedb
itself.
The index is being duplicated when you start from a new process and run the ensureIndex
function on an existing datastore file.
I verified this by doing the following:
node
interactive shell and ran the following commands:
Welcome to Node.js v12.22.6.
Type ".help" for more information.
> const Datastore = require('.')
undefined
> const datastore = Datastore.create("test.db")
undefined
> datastore.ensureIndex({ fieldName: 'test', unique: true })
Promise { <pending> }
> datastore.ensureIndex({ fieldName: 'test', unique: true })
Promise { undefined }
>
(To exit, press ^C again or ^D or type .exit)
After exiting the test.db
datastore file contained the following:
{"$$indexCreated":{"fieldName":"test","unique":true}}
node
interactive shell and exited, after which the test.db
file contained the duplicated index:
{"$$indexCreated":{"fieldName":"test","unique":true}}
{"$$indexCreated":{"fieldName":"test","unique":true}}
@seald-io/nedb
(instead of require('.')
- require('@seald-io/nedb')
) and I got the same result as I did using nedb-promises
.I am not sure whether this is intentional or not (maybe compacting the datastore would get rid of the duplicate index entries) so I suggest opening a discussion about this in @seald-io/nedb
.
Hi, this might be related to something I'm actively working on: https://github.com/seald/nedb/issues/9
If you can make a repro case on @seald-io/nedb
, I'd be interested.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
The function ensureIndex is duplicating the code in the .db file but the docs say: " No need to remove any ensureIndex though, if it is called on a database that already has the index, nothing happens."
Before app inits I have the db.ensureIndex({ fieldName: 'name', unique: true }) and the line of code written in the .db file is being duplicated.
I've tried the same with '@seald-io/nedb' and its not being duplicated.