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

add modifier $position to $push in minimongo #4312

Merged
merged 2 commits into from May 5, 2015
Merged

add modifier $position to $push in minimongo #4312

merged 2 commits into from May 5, 2015

Conversation

@dferber90
Copy link
Contributor

@dferber90 dferber90 commented May 2, 2015

Issue #4158.

Adds the $position modifier to $push in minimongo. Also adds tests.

Behavior of $push with multiple modifiers is documented here as

  1. Update array to add elements in the correct position.
  2. Apply sort, if specified.
  3. Slice the array, if specified.
  4. Store the array.

Details:
As described in the last paragraph here, if value of $position exceeds the size of the array to be modified, then the operation is the same as not using the $position at all.
The minimongo code I added still runs through the $position code path in that case. To short-circuit, you could add if (position < target[index].length) position = arg.$position here, which would result in running through the regular code path. I am not sure which behavior is desired, but it should not matter anyways.

benjamn added a commit that referenced this pull request May 5, 2015
Add modifier $position to $push in minimongo.
@benjamn benjamn merged commit 28ccf5d into meteor:devel May 5, 2015
1 check passed
1 check passed
@apollo-cla
default The author has signed the Meteor Contributor Agreement.
Details
@benjamn
Copy link
Member

@benjamn benjamn commented May 5, 2015

Looks great, thanks @dferber90!

@Slava
Copy link
Member

@Slava Slava commented May 5, 2015

But does it work when the position is -1? I don't remember all the details, but it used to have a special behavior like "prepend"

@benjamn
Copy link
Member

@benjamn benjamn commented May 6, 2015

The code currently throws if $position < 0.

@Slava
Copy link
Member

@Slava Slava commented May 6, 2015

Oh, I think I confused it with {$push: { "-1": "a" }} type of update. NVM.

@glasser
Copy link
Member

@glasser glasser commented May 14, 2015

@benjamn This new feature should be mentioned in History.md.

@dferber90 dferber90 deleted the dferber90:push-position branch Jul 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants