MongoDB Workflow Update Returning Null & Error

I have a workflow that is reformatting some data and supposed to update the records in a new collection. In the preview, everything looks good, but after running the block, it returns all null values and says [info] Error evaluating updatePropsLoop (iteration 821): Argument passed in must be a string of 12 bytes or a string of 24 hex characters or an integer.

The block is a loop that runs the MongoDB findOneAndUpdate method. The query is set to {"_id": {"$oid": {{value.idToUpdate}} }}. This is how I have been updating my MongoDB records in many other workflows with no issues. The preview shows that it should be passing:
{
"_id": {
"$oid": "6643db48fae3a8521531e3d8"
}
}

Update is set to: {
"$set": {"projectOrgs": {{ value.propDataUpdate }} }
}

image

Everything looks right to me, exactly like similar workflows I have run, and I can't figure out a reason why I would get an error about the arguement passed in as the mongoDB _id matches up with a record in my DB.

An update on this - A second loop, in the same workflow, using the same MongoDB resource, was able to update it's records, though there were several similar errors in the log, most of those updates went through.

Retool support team, this has been open for like a week with no response. I could use some help here.

Hey @Sam_S! Thanks for reaching out.

The error you're seeing certainly suggests that one of the object IDs in your dataset is malformed - specifically the 821st one. Where does the data that you're looping over come from? Are you able to inspect that dataset in order to confirm the validity of that ID?

@Darren I have reviewed the data thoroughly. The Id's are valid (See my screenshots). It's something else.

image

Thanks for confirming that there isn't anything obviously wrong with the dataset, at least. :thinking: It's definitely a valid filter format, as you mentioned, and the only way I can reproduce that particular error is by passing in an invalid hex string.

Can you share any details about how you've configured the loop block itself? Seeing the preceding blocks in the sequence might be helpful, as well.

Hi @Darren,

This issue was resolved for me during office hours. I had forgotten about the OID's that were linking records to other collections in the data. The issue was unrelated to the filter object.

To anyone else with this issue, MongoDB does not allow null OID's, including in the document as foreign keys. If you have a field for a foreign key but a specific record has no value for that key, set the key to an empty string rather than a null OID.

  • Sam