node-red / node-red/node-red-nodes
MongoDB - Is there a way to insert more than 1 document at 1 time
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 1.1k
- Forks
- 612
- Avg merge
- 13h 57m
- Merged PRs (30d)
- 3
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No source file or test is named. Start with the mongodb out node configuration shown in the flow, especially its insert operation and multi option, and trace how the incoming payload is passed to MongoDB. Done means the node can insert multiple documents from one message while reusing a single MongoDB connection.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, mongodb
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100