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

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

Open
Thalinda opened this issue Nov 10, 2020 · 3 comments
Open

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

Thalinda opened this issue Nov 10, 2020 · 3 comments

Comments

@Thalinda
Copy link

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

@jdpacini
Copy link

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").

@Thalinda
Copy link
Author

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

@jdpacini
Copy link

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.

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