From b665a265d8ec3b25c252ab20e308387c8c55233c Mon Sep 17 00:00:00 2001 From: Jessica Lord Date: Thu, 25 Jan 2018 09:42:51 -0500 Subject: [PATCH] docs(examples): add array filter example (#1647) --- test/functional/examples_tests.js | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test/functional/examples_tests.js b/test/functional/examples_tests.js index ac6bcadedc..052ac6b0a0 100644 --- a/test/functional/examples_tests.js +++ b/test/functional/examples_tests.js @@ -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(); + } + ); + }); + } + }); });