-
Notifications
You must be signed in to change notification settings - Fork 27
"Can't use add op without position" adding properties to object #12
Comments
It looks like the new code assumes that adds are only ever adding values to arrays maybe? Given how the spec is written, I'm not sure it's possible to write a complete Mongo update operation from just the patch document alone? Don't you need a copy of the target document so that you can test for whether or not the path targets properties which already exist, and whether or not they're objects / arrays? |
Actually, for this case at least, it seems like the spec can be handled without knowledge of the target object. We're dealing with the second and third cases from https://tools.ietf.org/html/rfc6902#section-4.1: Case 1 has been handled in the code, cases 2 and 3 both happen to map to $set, and that will have the desired effect regardless of whether or not the target location already exists. I'll see about making a pull request to cover this case. |
Any updates on this? |
When the PR wasn't accepted, I ended up going ahead and spending a day or so rolling our own module to do this, along the lines of my previous reply above; i.e. taking the existing document as an additional parameter so that operations can be applied with knowledge of the previous document. Sadly it is not open sourced, though I will ask if our company is okay with publishing it. |
@mrcranky that would be great! |
I have the same issue. would appreciate if you could share your solution @mrcranky. thanks! |
annual ping for @mrcranky to see if you were able to publish this 🙏 😁 |
Okay, so, pre-empting the next annual ping, I have some positive news. I left my previous job, which never got around to giving the go-ahead, and so have had enough time to make https://www.npmjs.com/package/rfc6902-mongodb which is another attempt at the same functionality. It's my first npm module / github open source project, so if folks want to test it out, issues can be reported here and I'll see about fixing them. |
Ah amazing! Thanks so much, @mrcranky, and congrats on your first package! I'll check this out when I'm next working on the relevant package of mine... might be a while, but I've starred your repo in the meantime and thanks so much for reporting back and publishing! 🎉 |
Thank you @mrcranky! Regarding the first package - it's awesome! |
Hi,
I think there's some kind of regression about following closed issue:
#6
With the latest npm version (1.0.0), I have following issue:
As you can see patch is fully correct and should result with
{$set: {newKey: "newValue"}}
.Thanks.
The text was updated successfully, but these errors were encountered: