Skip to content

Commit

Permalink
docs(examples): add array filter example (#1647)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jessica Lord authored Jan 25, 2018
1 parent d3e6be1 commit b665a26
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/functional/examples_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1192,4 +1192,36 @@ describe('Examples', function() {
});
}
});

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

test: function(done) {
const configuration = this.configuration;
const MongoClient = configuration.newClient();

MongoClient.connect(function(err, client) {
const db = client.db(configuration.db);
const collection = db.collection('arrayFilterUpdateExample');

// 3. Exploiting the power of arrays
collection.updateOne(
{ _id: 1 },
{ $set: { 'a.$[i].b': 2 } },
{ arrayFilters: [{ 'i.b': 0 }] },
function updated(err, result) {
assert.equal(err, null);
assert.equal(typeof result, 'object');
client.close();
done();
}
);
});
}
});
});

0 comments on commit b665a26

Please sign in to comment.