nedb icon indicating copy to clipboard operation
nedb copied to clipboard

How add new colum if the colum dosn't exist ?

Open Thalinda opened this issue 3 years ago • 3 comments

Hello i am developing application witch use the nedb (by the way it's great) now the issue is i have added some new fields to the database but the previous code don't have in the this fields in the database is there any way to add this filed in nedb and i can't clean slate the database since there can be 100 of files already there since user using the app right now

Thalinda avatar Nov 10 '20 20:11 Thalinda

If a field doesn't exist, NEDB will create it automatically (e.g. db.update({'foo.bar': 'value'}) will create a field of "bar" inside "foo").

jdpacini avatar Nov 10 '20 21:11 jdpacini

OK but now my issues is i need to check if the filed exist before reading is there any way since my code stop from there when it's didn't find the field. And thank you very much for quick response

Thalinda avatar Nov 12 '20 09:11 Thalinda

Maybe there is a better way to handle this, but without updating your database, you can provide a default value like let x = db.find({key: value}) || value;

I run into the same problem a lot too so I'm also interested to know if anyone has a better solution.

jdpacini avatar Nov 12 '20 16:11 jdpacini