Atlas trigger match expression fullDocument

Hello.

I am trying to set up the most basic trigger in Altas, but I only want it to run when the modified document has a particular array field at length 1. I have the full document option chosen.

I have tried a couple match expressions:

{
  "fullDocument.myArray": { "$size": 1 }
}

The trigger never fires

and this, less-precise

{
  "fullDocument.myArray": { "$exists": true }
}

The trigger always fires, even when this array does not exist.

Any thoughts on why neither seem to work correctly?

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:

  1. updating { a: 1, myArray: [ 1 ] } to { a: 1, myArray: [ 1 ], b: 1 }
  • From 1 element to 1 element
  • Trigger fired
  1. updating { a: 2, myArray: [ 1, 2 ] } to { a: 2, myArray: [ 1 ] }
  • From 2 elements to 1 element
  • Trigger fired
  1. updating { a: 6, myArray: [ ] } to { a: 6, myArray: [ 'a' ] }
  • From 0 elements to 1 element
  • Trigger fired
  1. updating { b: 1, myArray: [ 1 ] } to { b: 1, myArray: [ 1, 2 ] }
  • From 1 element to 2 elements
  • Trigger NOT fired
  1. 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

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.