[SERVER-64456] Use countDocuments() instead of count() to ensure accurate document count Created: 11/Mar/22  Updated: 29/Oct/23  Resolved: 14/Mar/22

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 6.0.0-rc0

Type: Bug Priority: Major - P3
Reporter: Christopher Caplinger Assignee: Christopher Caplinger
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Backwards Compatibility: Fully Compatible
Operating System: ALL
Participants:
Linked BF Score: 15

 Description   

Use "countDocuments" instead of "count" to ensure that we get an accurate count instead of an approximate count from metadata. Otherwise, the count can be inaccurate if a TTL pass happens concurrently with the count call when the access blocker is blocking writes. In this case, the TTL delete will fail and be rolled back, but count calls before the rollback is applied will still reflect the delete.

see https://github.com/mongodb/mongo/blob/731f87f94d327f83816ae5ef99732e8993d22a92/jstests/replsets/tenant_migration_collection_ttl.js#L80 



 Comments   
Comment by Githook User [ 14/Mar/22 ]

Author:

{'name': 'Christopher Caplinger', 'email': 'christopher.caplinger@mongodb.com', 'username': 'UnicodeSnowman'}

Message: SERVER-64456: Use countDocuments() instead of count() to ensure accurate document count
Branch: master
https://github.com/mongodb/mongo/commit/1512c333827379f6ae74a4e2cceeaadbe768ba04

Generated at Thu Feb 08 06:00:23 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.