3

We wanted to switch over from using MongoDB 4.2 to Cosmos DB, but realized that the thing preventing us to do so are Update (aggregation) Pipelines. MongoDB supports them, on Cosmos DB we get a weird looking error Expected type object but found array. which prompts us to believe they are not supported (as you provide an array of update stages as opposed to an update document).

Is there a way to achieve something similar with Cosmos DB methods?

Update pipelines in MongoDB allow you to update a document with multiple steps as one atomic operation. The pipeline currently looks kinda like this (stock-keeping system with keeping track of reservations):

  1. Set a field to a value, and set another field to a calculated value based on some input and some document fields
  2. Set a boolean flag in case the calculation from step 1 yielded 0 or less
  3. Set a DateTime flag to NOW in case calculation from step 2 triggered "false"
Stefan
  • 141
  • 1
  • 5
  • Can you please add the exact query (minus confidential data, if any) and the error message returned by the server. – Siddhesh Vethe Feb 13 '20 at 14:34
  • 1
    I have a similar issue. I attempted to attach a new key and copy value of an existing key to it for each document. This is the query I ran: db.collection.update({}, [{$set: {newKey: '$oldKey'}}], {"multi": true}). Error is: Expected type object but found array. – Akalanka Weerasooriya Sep 15 '20 at 08:49
  • Any updates on this? Currently fighting with CosmosDB and Prisma, as I can't run any updates on items due to this error which looks like Aggregation Pipelines are not supported, even though the documentation says they should be. – tpschmidt Dec 21 '21 at 12:49

0 Answers0