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

update() deletes other fields not explicitly stated in update query #16

Closed
IanButterworth opened this issue Mar 3, 2016 · 3 comments
Closed

Comments

@IanButterworth
Copy link

My understanding is that the update function should just affect the fields stated in the update query, but it seems to delete every other field in the record, leaving just the updated field.

oid = insert(collection,("a" => 1,"b"=>2,"c"=>3)
update(collection, ("_id" => did), ("a" => 323))

Result:
("a" => 323)

not
("a" => 323,"b"=>2,"c"=>3)

@ghost
Copy link

ghost commented Mar 3, 2016

mongo.db requires that you use special "update operators" in order to update specific fields, leaving the others as-is. This seems to be supported in the Julia implementation as suggested in the unit tests:

        update(
            collection,
            ("_id" => oid),
            set("hello" => "after")
            )

Note the set(...) operation. Without any update operators, mongo.db will replace the entire "document" (using mongo.db terminology), which means effectively removing any fields that aren't provided. For more info on this, see https://docs.mongodb.org/manual/reference/method/db.collection.update/#example-update-specific-fields

@ghost ghost closed this as completed Mar 3, 2016
@ghost
Copy link

ghost commented Mar 3, 2016

BTW this is another place where a small update to the docs would be greatly appreciated -- again, if it's not obvious then it's worth spelling out!

@IanButterworth
Copy link
Author

Great. That worked as promised. Thanks. I agree that it's not obvious. 'Set' should be listed as an alternative to 'inc' in the update example

This issue was closed.
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

1 participant