# Using arrayFilter option in node-red-mongodb node in node-red

**URL:** <https://discourse.nodered.org/t/using-arrayfilter-option-in-node-red-mongodb-node-in-node-red/26573>\
**Category:** General\
**Created:** [13 May 2020 07:41 UTC](https://discourse.nodered.org/t/using-arrayfilter-option-in-node-red-mongodb-node-in-node-red/26573 "2020-05-13T07:41:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kushan-athukorala](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kushan-athukorala/32/21830_2.png) [@kushan-athukorala](https://discourse.nodered.org/u/kushan-athukorala)\
**Post date:** [13 May 2020 07:41 UTC](https://discourse.nodered.org/t/using-arrayfilter-option-in-node-red-mongodb-node-in-node-red/26573/1 "2020-05-13T07:41:42Z")

</div>

Hi,

I want to update an specific array element in a mongodb document.

How can I pass arrayFilter option to the mongodb node when I do the update.

Thanks,  
Kushan

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [13 May 2020 09:47 UTC](https://discourse.nodered.org/t/using-arrayfilter-option-in-node-red-mongodb-node-in-node-red/26573/2 "2020-05-13T09:47:34Z")

</div>

Could you please explain a bit more? List out the seperate steps you are taking(planning on taking) to accomplish this.

Do you intend to retreive something from mongoldb and the result will have an array that you want to update an occurrence of that array then update the database with that result

OR do you want to send a value that, in an update statement, you want to change a particular occurance of a column in the database? How will you know what occurance to change?

(NOTE: not being a mongodb user, the 'terms' misght be incorrect - forgive me for that)

---

<div class="post-metadata">

**Author:** ![kushan-athukorala](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kushan-athukorala/32/21830_2.png) [@kushan-athukorala](https://discourse.nodered.org/u/kushan-athukorala)\
**Post date:** [13 May 2020 10:08 UTC](https://discourse.nodered.org/t/using-arrayfilter-option-in-node-red-mongodb-node-in-node-red/26573/3 "2020-05-13T10:08:47Z")

</div>

Hello zenofmud,

Thank you for your reply.

I have a mongodb document created using node-red-mongodb node.  
This document contains an embedded nested array. I want to update the value of one specific array element in the inner array.

To do that, I need to pass options with arrayFilter option as an argument to the node-red-mongodb node. but the node support only msg.projection and msg.payload.

However, from further reading I figured out that this node does not support this because options have been hard coded within. Therefore no way of using this for that purpose. I am now looking at node-red-contrib-mongodb3. I think this would give the results I need.

```auto
 else if (node.operation === "update") {
                            if (typeof msg.payload !== "object") {
                                msg.payload = {"payload": msg.payload};
                            }
                            var query = msg.query || {};
                            var payload = msg.payload || {};
                            var options = {
                                upsert: node.upsert,
                                multi: node.multi
                            };
                            if (ObjectID.isValid(msg.query._id)) {
                                msg.query._id = new ObjectID(msg.query._id);
                            }
                            coll.update(query, payload, options, function(err, item) {
                                if (err) {
                                    node.error(err,msg);
                                }
                            });
                        }

```

---

<div class="post-metadata">

**Author:** ![kushan-athukorala](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kushan-athukorala/32/21830_2.png) [@kushan-athukorala](https://discourse.nodered.org/u/kushan-athukorala)\
**Post date:** [18 June 2020 03:59 UTC](https://discourse.nodered.org/t/using-arrayfilter-option-in-node-red-mongodb-node-in-node-red/26573/4 "2020-06-18T03:59:51Z")

</div>

> [@kushan-athukorala](#):
>
> node-red-contrib-mongodb3

node-red-contrib-mongodb3 solved the problem

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [2 July 2020 03:59 UTC](https://discourse.nodered.org/t/using-arrayfilter-option-in-node-red-mongodb-node-in-node-red/26573/5 "2020-07-02T03:59:51Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
