Skip to content

MongoDB - Is there a way to insert more than 1 document at 1 time #1095

Description

@syafiqchezakaria

Hi.
Is there a way to insert more than 1 documents at one time?
This is example of my flow for inserting 1 document per trip (from function node to mongodb out node).

[ { "id": "ab1293da47f335a6", "type": "inject", "z": "e4313b973576809c", "name": "insert", "props": [ { "p": "payload" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "", "payloadType": "date", "x": 90, "y": 920, "wires": [ [ "60bbdc50c9cb93c2" ] ] }, { "id": "60bbdc50c9cb93c2", "type": "function", "z": "e4313b973576809c", "name": "insert function", "func": "let collection = 'daily-sale';\nlet payload = {\n 'day':1,\n 'sale': 1000,\n 'usage': 1000,\n 'collection': collection\n}\n\nlet obj = Object.assign({},payload);\nmsg.payload = obj;\nreturn msg.payload;", "outputs": 1, "timeout": 0, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 260, "y": 920, "wires": [ [ "886a25611356b391" ] ] }, { "id": "886a25611356b391", "type": "mongodb out", "z": "e4313b973576809c", "mongodb": "2c97b2ee28fbe18e", "name": "mongodb", "collection": "", "payonly": false, "upsert": true, "multi": false, "operation": "insert", "x": 440, "y": 920, "wires": [] }, { "id": "2c97b2ee28fbe18e", "type": "mongodb", "hostname": "mongodb", "topology": "direct", "connectOptions": "", "port": "27017", "db": "db", "name": "" } ]

My objective is to reduce resource usage by using only 1 connection to mongodb to insert multiple documents at one time.
Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions