Mongodb query

Hi

I am trying to use the mongodb query via the mondo node.

I have a property called “event.topic”: “radar_in_use”

In N8N (no results)

In 3t studio (1 result)

I have tried any thing i could i think about and could not find any documentation.

Kind regards
Mattias

Hm do currently not understand why it should not work. From what you described I guess your document looks something like this:

{
  "event" : {
    "topic" : "radar_in_use"
  },
 "something": "else"
}

So I created the following workflow which creates this document and then queries it directly. which worked fine for me. Can you please check if that is also the case for you.

For some reason did it work after i droped the collection in morgon and then created a new, but before that it did not work. Strange

Still thanks for the assistance.

That is very strange. Wonder what was going on there!

Anyway, for now happy to hear that it works.

Hi again!
I dont know if should create a new topic of it is fine to ask it here.

Everything with the look up is working fine but still my plan failed. I have talked with our devs aswell but could not find a solution.

I would like to store a mapping to an item in previous node inside in the json file (in mongo) Set pictures below. The stored mapping should then be used to get the data from a previous node. I know it might be a bit strange explanation but i hope the pictures explains it better.

We have tried JSON.parse but did not work .

Data from mongo
mongojsonnode

How it looks when i map it into the httprequest

How i would like it to work (This i achieved by manually copying the json into the node)

One again thanks for a great software:)

So if I understand it correctly do you have an n8n expression saved in your database and you want to then evaluate it after you read if from there? If that is the case, then it is currently sadly not possible. We would have to create and expose an additional function to do that. I added it to the To-Do list.

Ok thank you! Then it was not us:) Yeah if you be great to be able to parse the json back then i think it would work:)

Then i need to find a work around in the in the meantime:)

Ok that is now possible with the just released [email protected].

In expressions $evaluateExpression() and in Function-Nodes evaluateExpression() can be used.

The documentation about it can be found here:

An example workflow which uses all the different possibilities:

Thanks! Will try it directly! Thanks again for an amazing software, we will do anything we can to support it.

We tried it out but it is not really solve thing problem yet

We would like following

//This evaluation is working 
//"shipId" : "{{$node['Webhook'].json['body']['Location']['GlobalId']}}", 
items[0].json.string3a = evaluateExpression($node["MongoDB"].json["event"]["location"]["shipId"], 0);
-------------
But we would need
// We would like to evaluate the whole json. Json will include the expression as value of some properties  
items[0].json.string3a = evaluateExpression($node["MongoDB"].json, 0);

return items;

Ah yes, that would not work. Giving the whole objects is something very unique and a custom need and so should probably not be in n8n itself. At least do not expect that a lot of people would need that.
But that is not a problem. With the evaluateExpression function you can now solve that yourself. You can simply write your own custom code in a Function-Node which recursively goes through all the properties and then resolve the ones which, for example, start with “{”.

Okey thanks! I put one of the developers into it:)

Ah you can not yourself? Wait I have short look.

Well i guess i cant, still to much beginner on js;) You dont need to do it, Jens is already on it! I guess he will ask you if he don´t manage:)

Maybe could be good with some help, we got abit stucked with n8n nodes so an exmaple would be rreally helpful;)

The code is for sure not perfect but should cover the most cases:

THank you!

Works great! Will try to get better at this :slight_smile:

1 Like

Sorry for a long runner.

So now it works close to perfect. There is just one error we do not get why it occurs and we have tried everything.

When we have the json in function nodes it works perfectly

But when we place it with the real mongo DB then we get below error. The strange thing is when i then push only execute the failed node again then it works, but never on the first run.

ERROR: ‘getOwnPropertyDescriptor’ on proxy: trap reported non-configurability for property ‘0’ which is either non-existent or configurable in the proxy target

TypeError: 'getOwnPropertyDescriptor' on proxy: trap reported non-configurability for property '0' which is either non-existent or configurable in the proxy target
    at Function.keys (<anonymous>)
    at resolveData (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes:5:30)
    at resolveData (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes:6:25)
    at resolveData (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes:6:25)
    at /usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes:20:11
    at Object.<anonymous> (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes:24:2)
    at NodeVM.run (/usr/local/lib/node_modules/n8n/node_modules/vm2/lib/main.js:1043:29)
    at Object.execute (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Function.node.js:67:31)
    at Workflow.runNode (/usr/local/lib/node_modules/n8n/node_modules/n8n-workflow/dist/src/Workflow.js:557:37)
    at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/src/WorkflowExecute.js:370:62

Node with functions that works

The only thing I can think of right now is that the ID makes problems. The ID of Mongo documents is its own type and at the first run it is probably of that special type (and makes problems) and on the second run it got already converted to JSON and therefore it works.

You could try this node. It skips the “_id” property and makes instead sure that it gets directly converted to a “proper” string.

Thank you!

Now i will try to not disturb for a while:)