-
Notifications
You must be signed in to change notification settings - Fork 182
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
Inserting field with undefined
value inserts null
instead of undefined
#146
Comments
it's fixed in monk@3.0.6 |
Just tried with monk@3.0.6 and rather than inserting One nice thing about having The benefit of collection.findOne({ email: 'me@email.com' }).then(({ name = 'No name' }) => {
// yadda yadda
}); We can definitely delete undefined fields before inserting, but it would be nice to have some control over |
Indeed, it would be nice but the difference between I'll think about what we can do but I'm afraid it's not much |
maybe deleting the undefined fields on insert? |
undefined
value inserts null
instead of undefined
Yikes, I didn't realize the BSON spec deprecated Deleting the undefined fields on insert sounds like a great suggestion. That does seem to mimic the behavior of a javascript object more than having a null value. |
This can be implemented as a middleware (see https://automattic.github.io/monk/docs/middlewares.html) in user-land. Will close this as it probably shouldn't be core |
@mathieudutour can you show what the middleware would look like? |
hum maybe something like: module.exports = function (context) {
return function (next) {
return function (args, method) {
if (!args.data) {
return next(args, method)
}
if (typeof args.data !== 'object') {
return next(args, method)
}
const dataWithoutUndefined = Object.keys(args.data).reduce((prev, k) => {
if (typeof args.data[k] !== 'undefined') {
prev[k] = args.data[k]
}
return prev
}, {})
args.data = dataWithoutUndefined
return next(args, method)
}
}
} |
it seems like mongo has connection option |
For example:
inserts
{ name: {} }
and not{ name: undefined }
. I'm using monk 3.0.4.The mongo shell inserts
{ name: undefined }
for same insert command.The text was updated successfully, but these errors were encountered: