node-red-nodes icon indicating copy to clipboard operation
node-red-nodes copied to clipboard

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

Open syafiqchezakaria opened this issue 9 months ago • 2 comments

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.

syafiqchezakaria avatar May 24 '25 03:05 syafiqchezakaria

No, the mongo node from this repo does not support bulk insertion

There are a number of alternative nodes available when searching on flows.nodered.org

https://flows.nodered.org/search?term=mongo&type=node

p.s. please us the Node-RED forum or Slack to ask questions, we try to keep GitHub Issues for only defects with the code (we will fix the Issue template shortly to make this clear again).

hardillb avatar May 24 '25 06:05 hardillb

No, the mongo node from this repo does not support bulk insertion

There are a number of alternative nodes available when searching on flows.nodered.org

https://flows.nodered.org/search?term=mongo&type=node

p.s. please us the Node-RED forum or Slack to ask questions, we try to keep GitHub Issues for only defects with the code (we will fix the Issue template shortly to make this clear again).

I see. thank you @hardillb for the reply. Also im sorry for asking here. This is my first time asking on NodeRed. I really appreciate your help. Thank you so much.

syafiqchezakaria avatar May 24 '25 11:05 syafiqchezakaria