MongoDB - 'Must be valid JSON' Error

:wave:

I'm using a MongoDB instance as my database backend but am getting an error when trying to search for a specific object

I've tested my query in Compass and it is running fine - hopefully someone else has run into this problem!

In compass if I use find or match on ObjectId I return a single document that matches the chosen id - the format is as follows:
find {_id: ObjectId('distinct_id')}

However, when I put this into retool i get the following errors:
The value has to be of type 'object | void', you provided a value of type 'string'

message:"The value given - { _id:ObjectId("6234bc60a1aaac0045d2c7c5") } must be valid JSON."

Any help welcome! Cheers,

Iā€™m not familiar with MongoDB but maybe remove the quotes? Just throwing it out there

Hey @vicdavies01! Just out of curiosity, did Scott's suggestion of removing the quotes unblock you here? :slightly_smiling_face:

Hey @victoria - it didn't unfortunately, I instead had my dev team create an api to fetch specific details based on the company_id inputted. So same outcome different solution!

If you have any updates / suggestions happy to test out again for future use :blush:

Ah, got it! In Retool, we actually use extended JSON syntax so your query field would look something like this:

{ _id: { $oid: {{urlparams.hash.companyId}} } }

Let me know if that works for you + here are our MongoDB docs with some examples :slight_smile: https://docs.retool.com/docs/mongodb

**note: make sure to avoid triple (or more) curly braces. Keep the double curlies separate from all other curly braces! Having something like this will confuse Retool and it won't often render correctly:

{ $oid: {{urlparams.hash.companyId}} }

This should be fine though:

)}}, ]}}, etc.

Finally managed to get around to testing this and it works

One small issue / tip - remove the ; from the code in the knowledge base docs

Retool Docs
image

Implementation in my Query (shows error with the ;)

Implementation in my Query (removing the ;) :white_check_mark:

Thank you for posting this! Super helpful catch. I'll look into this now.