Uploaded image for project: 'Nuxeo Platform'
  1. Nuxeo Platform
  2. NXP-27953

Review and update deprecated usage of MongoCollection#count API

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 10.10-HF17, 11.1, 2021.0
    • Component/s: Core MongoDB
    • Backlog priority:
      1,000
    • Sprint:
      nxplatform 11.1.19, nxplatform 11.1.20
    • Story Points:
      3

      Description

      Context

      MongoCollection#count API has been deprecated in Mongo Driver 3.8 in favor of:

      • estimatedDocumentCount
      • countDocuments

      Current count implementation is superseded by the estimatedDocumentCount implementation and leverages collection metadata to count documents.

      New countDocuments executes an aggregation of documents to count them. The new API is more accurate as collection metadata can be refreshed asynchronously.

      From MongoDB documentation:

      Unlike db.collection.count(), db.collection.countDocuments() does not use the metadata to return the count. Instead, it performs an aggregation of the document to return an accurate count, even after an unclean shutdown or in the presence of orphaned documents in a sharded cluster.

      In some cases we can observe that the returned count is not enough accurate for our needs, this is the case on MongoDB directories in the drop and create vocabulary scenario detailed below:

      • drop the collection
      • executes a count filtered by entity id to create
      • create entity if count is 0 otherwise throw an error

      Improvement

      We want to review all of our usage of count API in Nuxeo Platform and choose the correct new API.

      CAUTION: countDocuments API is present on MongoDB 3.6 server or as stated on matrix compatibility (9.10 / 10.10), we support MongoDB 3.4.

      So for these two LTS, we need to check if we can use countDocuments by checking the MongoDB server version or with a configuration parameters on nuxeo side.. As it, we can provide accurate count for compatible setup.

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 1 week, 2 days
                  1w 2d