Hi @Heath_Volmer,
but I only want it to run when the modified document has a particular array field at length 1
I assume this trigger is only for operation type Updates
then - Is that correct?
I had the following test documents in my test environment:
[
{ a: 1, myArray: [ 1 ] },
{ a: 2, myArray: [ 1, 2 ] },
{ a: 3, myArray: [ 1, 2, 3 ] },
{ a: 4, myArray: [ 1, 2, 3, 4 ] },
{ a: 5, myArray: [ 1, 2, 3, 4, 5 ] },
{ a: 6, myArray: [ ] },
{ b: 1, myArray: [ 1 ] }
]
and the following match expression:
{
"fullDocument.myArray": {
"$size": {
"$numberInt": "1"
}
}
}
Please see the following tests performed and results:
- updating
{ a: 1, myArray: [ 1 ] }
to { a: 1, myArray: [ 1 ], b: 1 }
- From 1 element to 1 element
- Trigger fired
- updating
{ a: 2, myArray: [ 1, 2 ] }
to { a: 2, myArray: [ 1 ] }
- From 2 elements to 1 element
- Trigger fired
- updating
{ a: 6, myArray: [ ] }
to { a: 6, myArray: [ 'a' ] }
- From 0 elements to 1 element
- Trigger fired
- updating
{ b: 1, myArray: [ 1 ] }
to { b: 1, myArray: [ 1, 2 ] }
- From 1 element to 2 elements
- Trigger NOT fired
- updating
{ a: 3, myArray: [ 1, 2, 3 ] }
to { a: 3, myArray: [ ] }
- From 3 elements to 0 elements
- Trigger NOT fired
Hope this helps. However, if not, could you please provide some sample documents and the operations you’re executing (that would fire the trigger) so that I could try reproduce the behaviour you’re experiencing?
If you believe the above helps, please test thoroughly and verify it suits all your use case / requirements.
Regards,
Jason