How do I updateMany with the data api, and $oid

I’m trying to run an updateMany command with the data api, but I can’t figure out how to use $oid against an array of _ids. The workaround I landed on was

filter: { $or: _ids.map(_id => ({ _id: { $oid: _id } })) },

Is there a way to get a variation on one of these to work, though?

filter: { _id: { $in: { $map: { input: _ids, as: "$oid" } } } },
filter: { _id: { $in: { $oid: _ids } } },

Hi @Adam_Rackis,

Not too sure if this is what you are after but I managed to update 2 documents with the following:

curl --request POST \
  'https://data.mongodb-api.com/app/<Data API App ID>/endpoint/data/v1/action/updateMany' \
  --header 'Content-Type: application/json' \
  --header 'api-key: <Data API Key>' \
  --data-raw '{
      "dataSource": "Cluster0",
      "database": "todo",
      "collection": "tasks",
      "filter": { "_id": {"$in" : [{ "$oid": "6193ebd53821e5ec5b4f6c3b" },{ "$oid": "6193ebd53821e5ec5b4f6c3c" }] } },
      "update": {
          "$set": {
              "status": "updated"
          }
      }
  }'

More specifically, the filter value used was (against an array of $oids):

 "filter": { "_id": {"$in" : [{ "$oid": "6193ebd53821e5ec5b4f6c3b" },{ "$oid": "6193ebd53821e5ec5b4f6c3c" }] } }

The documents after the updateMany Data API request:

[
  { _id: ObjectId("6193ebd53821e5ec5b4f6c3b"), status: 'updated' },
  { _id: ObjectId("6193ebd53821e5ec5b4f6c3c"), status: 'updated' }
]

Note: Prior to the Data API request, the documents did not have a status field

Regards,
Jason

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