I am trying to setup a database trigger for an embedded object .
My Embedded Object is set up as :
"review_info" :{
"in_review" : boolean,
"date" : Date,
.....
}
I am trying to run a database trigger, when a document is updated and in_review is set to true.
For that the query in my trigger configuration is set as ::
{
"updateDescription.updatedFields" : {
"review_info.in_review": true
}
}
So when I change the “review_info.in_review” manually from mongo data services (collections), the trigger is working fine, but if the same data is changed from client app (which is a flutter app with atlas device sync sdk (realm)), I am getting the error :
``error in read messages loop: could not decode next message: failed to get reader: WebSocket closed: failed to acquire lock: context deadline exceeded`
The funny thing is if i set up the query as :
{
"updateDescription.updatedFields" : {
"review_info": { "$exists" : true}
}
}
The trigger works fine.
Hi, as a first comment, I think the error message you posted about the context deadline exceeded is a red herring, its just a normal error when an operation in MongoDB or the Websocket to the server is taking too long, so it restarts and relies on the client reconnecting and the Device Sync protocol handles everything just fine.
As for your issue, you are getting into some of the oddities when it comes to change events. For example:
{
"updateDescription.updatedFields" : {
"review_info": { "$exists" : true}
}
}
This only matches when a single field in the object is updated and that field is review_info. If multiple fields are updated, then this will not match because the expression is explicitly querying for when the updatedFields field in the change event is equal to the expression within that statement.
I would advise you to modify this to be:
{
"updateDescription.updatedFields.review_info.in_review" : true,
}
That being said, I would generally push you to not use a match expression and to define your logic directly in the function code itself unless you are dealing with a very large scale of events.
If you do choose to use a match expression, I would pay very close attention both to the format of change events (I would take a look at them using the shell and listen to events on the collection), and to the exact syntax of the match expression that you are using.