Thanks for testing that, @zean_validated! This is the thread that I was referencing earlier. For that particular case, I verified that wrapping the operation object in brackets fixed the issue.
Remind what kind of operation you're wanting to perform here - is it an insert or update?
Hi @zean_validated, after some testing I found something to consider:
With this condition: if: { $ne: [{{ fbAccountId.value }}, null] }
We are checking if the value of fbAccountId is not null. Is fbAccountId a variable, column, or an input? If it's an input, it will evaluate to "" when there is no value (the user has not typed in), so we should use "" instead of null.
Thanks for the investigation. I've implemented these ideas, but I'm still hitting some snags.
First, I should note that I'm using the syntax for insertOne β wrapping in square brackets yields a "BSON field 'insert.documents.0' is the wrong type 'array', expected type 'object'" error:
@Paulo FWIW I would use updateOne as you suggested, but this operation is only run to create new records, and passing {} as the filter doesn't seem to do anything.
Appreciate the update, @zean_validated! I couldn't remember if this was an insert or update operation.
I'm still trying to narrow down exactly where the issue here is occurring - if it's a limitation of the Extended JSON syntax as it pertains to document creation or the result of typecasting/parsing that is happening on the Retool side.
In the meantime, my recommendation is to just construct the entire document JSON within curly braces. This allows you to perform fairly complex conditionals as long as you only need access to data within Retool.
For more complex objects, you could even move all the logic for constructing the document into a separate JS query. I'll provide an update here when I have a more concrete answer about using MongoDB aggregates and other functions but hopefully this unblocks you for the time being!
@Darren thanks for the suggestion β I've tried to employ this in several ways. It's successful when inserting a single-field document, but I'm still encountering syntax errors when trying to insert a multi-field document.
Here's my 1:1 implementation of your suggested logic: