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

feat(Update): add the ability to specify a pipeline to an update command #2017

Merged
merged 5 commits into from Jun 12, 2019

Conversation

spal1
Copy link
Contributor

@spal1 spal1 commented Jun 10, 2019

Fixes NODE-1920

Description

This provides extended functionality for the update command by allowing the specification of a pipeline. update can now take in an object or an array.

What changed?
To allow the user to pass in an array to update in addition to preserving the functionality of providing an object, the corresponding argument in the updateOne function was modified to check for atomic operators on each element in the array, if passed in as such.

@@ -686,7 +686,10 @@ Collection.prototype.updateOne = function(filter, update, options, callback) {
if (typeof options === 'function') (callback = options), (options = {});
options = options || {};

const err = checkForAtomicOperators(update);
const err = Array.isArray(update)
? update.forEach(checkForAtomicOperators)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from what I can tell, this is not going to return an err, as Array.prototype.forEach returns undefined.

Is the goal here to get the first checkForAtomicOperators error on the pipeline?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I believe that we want the first checkForAtomicOperators error in the pipeline.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case you could build this up imperatively:

let err;
if (Array.isArray(update)) {
  for (let i = 0; !err && i < update.length; i++) {
    err = checkForAtomicOperators(update);
  }
} else {
  err = checkForAtomicOperators(update);
}

it('should correctly update with pipeline', {
metadata: {
requires: {
topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK we don't use the heap and wiredtiger environments anymore.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can handle this by remove this entire line, which will cause this test to run for every topology that we run them against.

Copy link
Contributor

@kvwalker kvwalker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great overall!

it('should correctly update with pipeline', {
metadata: {
requires: {
topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can handle this by remove this entire line, which will cause this test to run for every topology that we run them against.

[{ $set: { a: 1 } }, { $set: { b: 1 } }, { $set: { d: 1 } }],
configuration.writeConcernMax(),
(err, r) => {
expect(err).to.equal(null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use expect(err).to.not.exist.

configuration.writeConcernMax(),
(err, r) => {
expect(err).to.not.exist;
expect(r.result.n).to.equal(0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we expect this to be 0?

Copy link
Contributor

@kvwalker kvwalker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor

@daprahamian daprahamian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@spal1 spal1 merged commit 87ef7bf into mongodb:next Jun 12, 2019
daprahamian pushed a commit that referenced this pull request Aug 13, 2019
…and (#2017)

* feat(Update): add the ability to specify a pipeline to an update command

NODE-1920
rosemaryy pushed a commit to rosemaryy/node-mongodb-native that referenced this pull request Aug 16, 2019
…and (mongodb#2017)

* feat(Update): add the ability to specify a pipeline to an update command

NODE-1920
rosemaryy pushed a commit to rosemaryy/node-mongodb-native that referenced this pull request Aug 16, 2019
…and (mongodb#2017)

* feat(Update): add the ability to specify a pipeline to an update command

NODE-1920
rosemaryy pushed a commit to rosemaryy/node-mongodb-native that referenced this pull request Aug 19, 2019
…and (mongodb#2017)

* feat(Update): add the ability to specify a pipeline to an update command

NODE-1920
mbroadst pushed a commit that referenced this pull request Sep 21, 2019
…and (#2017)

* feat(Update): add the ability to specify a pipeline to an update command

NODE-1920
mbroadst pushed a commit that referenced this pull request Oct 8, 2019
…and (#2017)

* feat(Update): add the ability to specify a pipeline to an update command

NODE-1920
mbroadst pushed a commit that referenced this pull request Oct 10, 2019
…and (#2017)

* feat(Update): add the ability to specify a pipeline to an update command

NODE-1920
mbroadst pushed a commit that referenced this pull request Oct 10, 2019
…and (#2017)

* feat(Update): add the ability to specify a pipeline to an update command

NODE-1920
mbroadst pushed a commit that referenced this pull request Oct 14, 2019
…and (#2017)

* feat(Update): add the ability to specify a pipeline to an update command

NODE-1920
mbroadst pushed a commit that referenced this pull request Oct 15, 2019
…and (#2017)

* feat(Update): add the ability to specify a pipeline to an update command

NODE-1920
daprahamian added a commit that referenced this pull request Oct 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants