# Insert into MongoDB - Only allows msg.payload object

**URL:** <https://discourse.nodered.org/t/insert-into-mongodb-only-allows-msg-payload-object/2258>\
**Category:** General\
**Created:** [13 August 2018 17:13 UTC](https://discourse.nodered.org/t/insert-into-mongodb-only-allows-msg-payload-object/2258 "2018-08-13T17:13:27Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![d0ublei](https://avatars.discourse-cdn.com/v4/letter/d/ba9def/32.png) [@d0ublei](https://discourse.nodered.org/u/d0ublei)\
**Post date:** [13 August 2018 17:13 UTC](https://discourse.nodered.org/t/insert-into-mongodb-only-allows-msg-payload-object/2258/1 "2018-08-13T17:13:27Z")

</div>

I am having an issue inserting something other than the msg.payload object into Mongo. I have a JSON object I am trying to insert. I Convert and Format the Object to a JSON string and then insert it into Mongo, however I am getting the error message "RangeError: Maximum call stack size exceeded".

To test, I copied the output JSON string and did a document insert straight from Robomongo. It inserted correctly. It seems to just be an issue with how the Node-Red insert is working. Any help would be much appreciated! Note, that just turning on insert msg.payload works perfect, it is just not Keyed correctly in the database( See SS) [NodeRedErros|302x424](https://discourse.nodered.org/404)

 ![Capture](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/5/500a8e18c5d73fda5a285f1f2fc05afa7e46916b.jpeg)

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [13 August 2018 17:19 UTC](https://discourse.nodered.org/t/insert-into-mongodb-only-allows-msg-payload-object/2258/2 "2018-08-13T17:19:28Z")

</div>

Try sending the JSON string inside an array [{JSON}]

---

<div class="post-metadata">

**Author:** ![d0ublei](https://avatars.discourse-cdn.com/v4/letter/d/ba9def/32.png) [@d0ublei](https://discourse.nodered.org/u/d0ublei)\
**Post date:** [13 August 2018 19:08 UTC](https://discourse.nodered.org/t/insert-into-mongodb-only-allows-msg-payload-object/2258/3 "2018-08-13T19:08:00Z")

</div>

Thanks @ghayne that works. It is still entering the string as a payload key in the DB (see screenshot). Is this node designed to enter things other than message payload?

 ![NodeRedIssue](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/e/ea9b6da644d2afd36647edbf3e19f2d3922b5926.jpeg)

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [13 August 2018 19:59 UTC](https://discourse.nodered.org/t/insert-into-mongodb-only-allows-msg-payload-object/2258/4 "2018-08-13T19:59:12Z")

</div>

It might be easier to answer your question if you specified which node you are using [https://flows.nodered.org/?term=mongodb&type=node&num\_pages=1](https://flows.nodered.org/?term=mongodb&type=node&num_pages=1)

---

<div class="post-metadata">

**Author:** ![d0ublei](https://avatars.discourse-cdn.com/v4/letter/d/ba9def/32.png) [@d0ublei](https://discourse.nodered.org/u/d0ublei)\
**Post date:** [13 August 2018 20:09 UTC](https://discourse.nodered.org/t/insert-into-mongodb-only-allows-msg-payload-object/2258/5 "2018-08-13T20:09:34Z")

</div>

Sure, I am using:

> **[node-red-node-mongodb](https://flows.nodered.org/node/node-red-node-mongodb)**
>
> Node-RED nodes to talk to an Mongo database

  
Version 0.0.14

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [13 August 2018 21:04 UTC](https://discourse.nodered.org/t/insert-into-mongodb-only-allows-msg-payload-object/2258/6 "2018-08-13T21:04:18Z")

</div>

From the node info:

" MongoDB only accepts objects.

Save and insert can either store `msg` or `msg.payload` . If msg.payload is selected it should contain an object. If not it will be wrapped in an object with a name of payload."

---

<div class="post-metadata">

**Author:** ![d0ublei](https://avatars.discourse-cdn.com/v4/letter/d/ba9def/32.png) [@d0ublei](https://discourse.nodered.org/u/d0ublei)\
**Post date:** [13 August 2018 21:19 UTC](https://discourse.nodered.org/t/insert-into-mongodb-only-allows-msg-payload-object/2258/7 "2018-08-13T21:19:22Z")

</div>

@ghayne made a good point, it looks like this node is really just made to input msg.payload values. After years of being in the industry, i should have learned how to read documentation by now.

I just corrected the issue here is how I did it:  
There is another node, node-red-contrib-mongodb3 which allows for many more operations to be carried out on the database. By using this and just passing a JSON string, I was able to input my data correctly

Hope this helps some other people, in short, just use node-red-contrib-mongodb3 if you want to carry out operations in Mongo.

---

<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 August 2018 21:29 UTC](https://discourse.nodered.org/t/insert-into-mongodb-only-allows-msg-payload-object/2258/8 "2018-08-13T21:29:09Z")

</div>

> [@d0ublei](#):
>
> After years of being in the industry, i should have learned how to read documentation by now.

Hmmm...what a novel Idea 🤣

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [13 August 2018 21:29 UTC](https://discourse.nodered.org/t/insert-into-mongodb-only-allows-msg-payload-object/2258/9 "2018-08-13T21:29:36Z")

</div>

It'll never catch on...

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [14 August 2018 08:52 UTC](https://discourse.nodered.org/t/insert-into-mongodb-only-allows-msg-payload-object/2258/10 "2018-08-14T08:52:12Z")

</div>

> [@dceejay](#):
>
> It'll never catch on...

A universal truth! Except for old Hewlett Packard calculator manuals, which are things of beauty.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [14 August 2018 10:11 UTC](https://discourse.nodered.org/t/insert-into-mongodb-only-allows-msg-payload-object/2258/11 "2018-08-14T10:11:59Z")

</div>

Didn't they use reverse Polish notation ? which would need a very good manual !

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [14 August 2018 10:21 UTC](https://discourse.nodered.org/t/insert-into-mongodb-only-allows-msg-payload-object/2258/12 "2018-08-14T10:21:02Z")

</div>

I still use RPN! Unfortunately I sold my HP41C, and my beloved HP71B, which was my introduction to BASIC programming. Now reduced to a HP15C Android app.
