-
Notifications
You must be signed in to change notification settings - Fork 4
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
Undefined properties are set to null in Mongodb #30
Comments
@jmdobry is this caused by the adapter or js-data v3 schema validation? |
Interesting, I'll have to give it a try. If the MongoDB driver was sane, it would treat |
I look at the MongoDB Driver documentation for DB class, there is an option that can be set to the DB instance So an other possible solution that works is to set MongoClient.connect(opts.uri, {
db: {
ignoreUndefined: true
}
}, (err, db) => {
if (err) {
return reject(err)
}
this._db = db
resolve(db)
}) I will try to investigate further why this behavior is not the default one. |
More infos found here : https://github.com/christkv/mongodb-core/issues/31, Automattic/mongoose#3169 |
@danivek thx for the leg work on the mongo driver opts! |
Description
versions :
js-data: 3.0.0-rc.6
js-data-mongodb : 1.0.0-rc.1
Steps to reproduce
Here is my model schema :
When i insert or update not all the properties of my model (example with only property "a" :
{a: "a"}
), the others properties are set toundefined
by js-data. So the inputprops
of methodscreate
orupdate
looks like :The problem is that the Node.js mongodb driver, insert
null
in the database for all theundefined
properties. So when you just want to update property "a", the previous value of property "b" is erase by anull
value.The workaround solution i found, is to remove all undefined properties of the object in methods
beforeCreate
andbeforeUpdate
on the adapter. But i think it could be made directly on insert or update methods.Solution can be found here : http://stackoverflow.com/questions/286141/remove-blank-attributes-from-an-object-in-javascript. It should be recursive and only remove undefined properties.
Any thoughts ?
Thanks!
The text was updated successfully, but these errors were encountered: