Simple MongoDB find by _id? [GOT CREATED]

Ok so perhaps I’m overlooking something really simple, or perhaps it’s unsupported at this time. I’ve done the work elsewhere to find an _id of interest, and now I would like to fetch the document and start operating on the data.

I have tried what I believe to be every permutation of quoting & nomenclature on the ‘find’ query for MongoDB but am unable to return the record of interest. I’ve reviewed the actual node definition and see the passthrough nature of the query section, but I can’t call the ‘ObjectID’ function of the module which mongo seems to require.

Example Expression:
{"_id":“ObjectId(‘5a17224770a39f0024481dab’)”}

So my question: Is it at all possible within N8N to directly look-up a mongodb record using it’s key?
Thanks in Advance.

Welcome to the community @jtolly

Sadly that is currently not possible. The _id property should be parsed to an ObjectID. Just made this post a feature request.

1 Like

A date for this feature? That would be insane!

Did just get added. With the next version it converts the string that is set as _id to an ObjectID. Will update here once it got released (probably tomorrow).

1 Like

Got released with [email protected]

What about fields that are not “_id”? For example foreign keys will have a different key name, but require querying using ObjectIds. Not sure if it’s feasible, but it would probably make a lot more sense to work with MongoDB using the mongo shell. It’s very difficult to express some queries in pure JSON form, so all MongoDB query IDEs usually allow you to interact with a shell instead.

Personally, instead of a bunch of allowed operations (like Find, or Aggregate), I’d rather just have the flexibility to run a mongo shell script.

A couple of other things this would allow you to do, but that can’t be done today.

{"_id": ObjectId("000000000000000000000000")}
{"otherIdField": ObjectId("000000000000000000000000")}
{"timestamp": {"$gte": ISODate("...")}}

Not having this is, unfortunately, a deal breaker.

3 Likes

Anyone got to work with ObjectId or ISODate?

@lehno This is the flow that routinely works for me If I need to access records in a time window. Hopefully it helps you

For some reason I can’t use $expr with my mongo. Its document DB hosted on AWS. It uses version 3.6. It might be $expr is not present in this version