[SERVER-42097] .count() returns wrong value Created: 07/Jul/19 Updated: 08/Jul/19 Resolved: 08/Jul/19 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Querying |
| Affects Version/s: | 3.2.22 |
| Fix Version/s: | None |
| Type: | Question | Priority: | Major - P3 |
| Reporter: | Yura Inversion | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Participants: |
| Description |
|
While debugging a problem in an app I found that it is caused by a wrong value returned from Mongo. So I end up have a collection for which .count() always returns 136 while the collection is empty. Here is what I see in the mongo terminal:
When I do dump — this collection is saved as PendingRecords.bson 0 B file. So it is really empty. And according to our log of logic actions, it really should be empty.
Repair helped, but what could go wrong? What should we do to do not encounter this again? Because it just breaks our app ( |
| Comments |
| Comment by Yura Inversion [ 07/Jul/19 ] | |||||||
|
Thank you for the information — now I understand the issue. It is really an old version. | |||||||
| Comment by Asya Kamsky [ 07/Jul/19 ] | |||||||
|
Are you really on 3.2.22? That's a very old version. In more recent versions you can use db.coll.countDocuments() to get a real count even without a predicate. | |||||||
| Comment by Daniel Pasette (Inactive) [ 07/Jul/19 ] | |||||||
|
Hi Yuba, looks like you found the issue – count without a query predicate ("fast count") can drift after an unclean shutdown. See this documentation on how to correct the issue. | |||||||
| Comment by Yura Inversion [ 07/Jul/19 ] | |||||||
|
I remember that this instance of mongod recently crashed once during active processing. So probably this can be a reason. In a log I found that moment — there was no exit signal
|