Strange question about mongodb indexing the actual written data index is not completed, so the query cannot be completed.

for example, the script is constantly writing data (the data level is very deep. The), tail-f log can see that it has been written to 10000 items, and it is also possible to find this piece of data in mongodb, but the direct count has only 9800 items of data and has been lagging behind 200. there are about 9 indexes related to this data (don"t ask me why I have so many indexes. I don"t want to. I also can"t decide) the property background of the index is true. Can it be considered that when an index is used, it can"t be queried if the data index has not been built?

Apr.30,2021

you need to take a look at the execution plan:

db.<>.explain(true).count(<>);

from this you can see whether an index can be used when count is used, and which index to use. The index of
{background: true} only does not block the foreground thread when it is created for the first time, and does not mean creating the index asynchronously, so there is no problem as you mentioned.
is more likely that one or more of these nine indexes are partial index , which is selected in the execution plan. You can view the index configuration

db.<>.getIndexes();

usually MongoDB is unlikely to choose such an index to get count, so it is also possible that a specific version of bug, would like to see your server version to confirm:

db.serverBuildVersion();

to sum up, we need to see:

  • execute the plan
  • configuration of 9 indexes
  • MongoDB version
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eaad29-2007.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eaad29-2007.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?