Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions test/functional/operation_array_update_example_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
'use strict';
const setupDatabase = require('./shared').setupDatabase;
const expect = require('chai').expect;

describe('Array Filter Update Example', function() {
before(function() {
return setupDatabase(this.configuration);
});

it('supports using array filters when updating one', {
metadata: {
requires: {
mongodb: '>=3.6.x',
topology: ['single']
}
},

test: function(done) {
const configuration = this.configuration;
const client = configuration.newClient(configuration.writeConcernMax(), { poolSize: 1 });
client.connect(function(err, client) {
const db = client.db(configuration.db);
const collection = db.collection('arrayFilterUpdateExample');

// 3. Exploiting the power of arrays
Copy link
Member

Choose a reason for hiding this comment

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

also does this line need a corresponding end tag?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will check with the docs team 👍

collection.updateOne(
{ _id: 1 },
{ $set: { 'a.$[i].b': 2 } },
{ arrayFilters: [{ 'i.b': 0 }] },
function updated(err, result) {
expect(err).to.equal(null);
expect(result).to.exist;
client.close();
done();
}
);
});
}
});
});