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

Conversation

Projects
None yet
4 participants
@dferber90
Contributor

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

Merge pull request #4312 from dferber90/push-position
Add modifier $position to $push in minimongo.

@benjamn benjamn merged commit 28ccf5d into meteor:devel May 5, 2015

1 check passed

default The author has signed the Meteor Contributor Agreement.
Details
@benjamn

This comment has been minimized.

Member

benjamn commented May 5, 2015

Looks great, thanks @dferber90!

@Slava

This comment has been minimized.

Member

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

This comment has been minimized.

Member

benjamn commented May 6, 2015

The code currently throws if $position < 0.

@Slava

This comment has been minimized.

Member

Slava commented May 6, 2015

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

@glasser

This comment has been minimized.

Member

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