UpdateMany with aggregation pipeline returns all documents updated

Hello,

It seems the doc does not refer to that particular return of the UpdateMany with aggregation pipeline
here => https://www.mongodb.com/docs/manual/reference/method/db.collection.updateMany
and here => https://www.mongodb.com/docs/manual/tutorial/update-documents-with-aggregation-pipeline

Do you think it’s possible to say to MongoDB to not return all documents from the aggregation pipeline? I have some stupid amount of documents returned and I’m a bit concerned about the next few months of my application. I’m afraid of blowing up my atlas server.

Hello @huneau_romain, welcome to the MongoDB community forum!

As per the documentation, I see that: The updateMany method returns a document that contains:

  • A boolean acknowledged as true if the operation ran with write concern or false if write concern was disabled
  • matchedCount containing the number of matched documents
  • modifiedCount containing the number of modified documents
  • upsertedId containing the _id for the upserted document

You may want to include some more information about the update method you are trying (for example, the code and also a sample document of the collection , after any redaction), to figure what the issue is.

1 Like

all requetes from mongodb atlas

querry

{
  "command": {
    "q": {
      "companyId": "cjwrneklvn"
    },
    "u": [
      {
        "$set": {
          "daysLate": {
            "$cond": {
              "if": {
                "$ifNull": [
                  "$closingDate",
                  false
                ]
              },
              "then": {
                "$round": [
                  {
                    "$divide": [
                      {
                        "$subtract": [
                          "$closingDate",
                          "$dueDate"
                        ]
                      },
                      {
                        "$multiply": [
                          1000,
                          3600,
                          24
                        ]
                      }
                    ]
                  }
                ]
              },
              "else": {
                "$round": [
                  {
                    "$divide": [
                      {
                        "$subtract": [
                          {
                            "$date": "2022-06-03T02:34:03.306Z"
                          },
                          "$dueDate"
                        ]
                      },
                      {
                        "$multiply": [
                          1000,
                          3600,
                          24
                        ]
                      }
                    ]
                  }
                ]
              }
            }
          }
        }
      }
    ],
    "multi": true,
    "upsert": false
  },
  "planSummary": [
    {
      "IXSCAN": {
        "companyId": 1,
        "id": 1
      }
    }
  ],
  "keysExamined": 104968,
  "docsExamined": 104968,
  "nMatched": 104968,
  "nModified": 15569,
  "keysInserted": 0,
  "keysDeleted": 0,
  "numYields": 827,
  "queryHash": "7AE1622F",
  "planCacheKey": "FB3DF234",
  "locks": {
    "ParallelBatchWriterMode": {
      "acquireCount": {
        "r": 828
      }
    },
    "ReplicationStateTransition": {
      "acquireCount": {
        "w": 828
      }
    },
    "Global": {
      "acquireCount": {
        "w": 828
      }
    },
    "Database": {
      "acquireCount": {
        "w": 828
      }
    },
    "Collection": {
      "acquireCount": {
        "w": 828
      }
    },
    "Mutex": {
      "acquireCount": {
        "r": 15570
      }
    }
  },
  "flowControl": {
    "acquireCount": 828,
    "timeAcquiringMicros": 850
  },
  "storage": {
    "data": {
      "bytesRead": 33901684,
      "timeReadingMicros": 66216
    }
  },
  "millis": 3213,
  "v": "4.2.20"
}

@huneau_romain, the screenshot you are looking at is the Atlas UIs Profiler TAB. And, the update query shows the query filter and the update. The planSummary is the query plan details.

This detail tell how many documents are matched and are updated/modified.

  "nMatched": 104968,
  "nModified": 15569,

Additional details about the Profiler:

1 Like

Yes, I agree with you but the profiler told us that 104968 key was examined and 104968 docs were returned.
I’m concerned about docs returned that have to be 0.

I’m just figured it out that nreturned field is not present inside the MongoDB explain thing.

This morning I launched the query ant I got the 104968 result. Now I relaunched it and I got nothing

@huneau_romain here is the link to Query Plan output examples. You can see various fields in the output and their meaning. Hope it clarifies some things.