Mongo db driver c# operations with nested array


imagine the following scenario:

             name: Blue,
             description: "This is blue"
             name: Green.
             description: "This is green"

I want to be able to perform an upsert based on the following contraints:

  1. if testId does not exist, inserts a new root document.
  2. if testsId exists, check colors. if colorId exists, update existing color, else inserts new element in colors array.

I am able to solve this problem using several separate operations such as:
find the document by testId, perform update and then upsert.

Can this be performed in a single operation using mongodb c# driver? What would be the best way, performance-wise, to do this?

Thanks in advance

I am struggling with a similar problem… Can somebody please help with some ideas? Thanks!