I’m using the findOne function on a MongoDB Atlas Function … I’m trying to match multiple data points but it doesn’t seem to match on these. I definitely have a document in my collection that matches however it always returns ``null`.
that is, the back tick and ${}, aka template literals will generate string values for your query. So if object_id and user_id in your documents are anything other than strings the query will not work event if event.fullDocument.object_id and event.fullDocument.user_id are not strings.
Exactly, thanks Steevej for elaborating on my reply, it could have been a touch more in-depth but this is exactly the point, you could be comparing ObjectIDs to strings which will not match and result in no results. Something else to try when debugging is to put the filter you’re creating in a variable and log that to the console. You can then take what it being run and try it out in a script window to investigate further.
Hi both,
Sorry for the late reply, and thank you for your help. Yes those were definitely both strings, but I have been having issues relating to date objects in MongoDB, and I think that was causing the error.