mongodb fix incorect result cursor count
When i try to fix a field on mongodb collection, i need to do an operation which cheap on cpu and memory usage, and i think i need do a process with limit and skip into specific value, just like pagination, but i got different result when i count all database and iterate over the cursor, and result from stats show the same results with count.
> db.articles.count()
6027
> db.articles.find().toArray().length
17587
> db.articles.stats()
{
"ns" : "nolimit.articles",
"count" : 6027,
"size" : 21906515,
...
i know that count operations do the same thing with the stats, when i try to read the whole page, i stop about inacurracy count due to unclean shutdown of mongod and the page told me to do validate to fix it.
And yes, validate process, make the count result fixed.
> db.articles.validate()
{
"ns" : "nolimit.articles",
"nrecords" : 17587,
"nIndexes" : 4,
"keysPerIndex" : {
"nolimit.articles.$_id_" : 17587,
"nolimit.articles.$date_created_1" : 17587,
"nolimit.articles.$date_created_-1" : 17587,
"nolimit.articles.$title_text_content_text_link_text" : 0
},
"valid" : true,
"errors" : [ ],
"warning" : "Some checks omitted for speed. use {full:true} option to do more thorough scan.",
"ok" : 1
}
> db.articles.count()
17587