This repository was archived by the owner on Dec 7, 2023. It is now read-only.
Open
Conversation
benpankow
reviewed
Nov 21, 2019
Contributor
benpankow
left a comment
There was a problem hiding this comment.
Generally looks good, a few notes inline.
| /* | ||
| Finds an item based on the given selector and patches it with the data in update | ||
| */ | ||
| func (db *MongoDatabase) Patch(collection_name string, selector interface{}, update *map[string]interface{}) error { |
Contributor
There was a problem hiding this comment.
If it's not a lot of extra effort, it would be nice to have update be an interface{} to match the signature of the other database functions. Not a big deal if not.
| collection := current_session.DB(db.name).C(collection_name) | ||
|
|
||
| // Use mongodb set operator to update only the provided fields. | ||
| err := collection.Update(selector, bson.M{"$set": update}) |
Contributor
There was a problem hiding this comment.
It's my understanding that this will only merge top-level changes, not nested fields. If so, it might be worth noting this in the comment above.
ie
{
"foo": {
"bar1": 1,
}
}
merged with
{
"foo": {
"bar2": 2,
}
}
results in
{
"foo": {
"bar2": 2,
}
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I added
Patchmethod inmongo_database.goto enable updates of only the selected fields in an entry.This method can be used by the patch methods in endpoints such as registration, blobstore, etc.
I also modified the
Database interfaceindatabase.goto reflect the change.