MongoDB: query result size is larger than collection size

I am analyzing a MongoDB data source to check its quality. I am wondering if each document contains a time attribute: so I used two commands

 > db.droppay.find().count(); 291822 > db.droppay.find({time: {$exists : true}}).count() 293525 

How can I have more elements with a given field than elements contained in an entire collection? Something went wrong? I can not find the error. If necessary, I can publish to you the expected structure of the document.

Mongo Shell version is 1.8.3. Mongo Db version is 1.8.3.

Thanks in advance


This is the expected document record structure:

 { "_id" : ObjectId("4e6729cc96babe974c710611"), "action" : "send", "event" : "sent", "job_id" : "50a1b7ac-7482-4ad6-ba7d-853249d6a123", "result_code" : "0", "sender" : "", "service" : "webcontents", "service_name" : "webcontents", "tariff" : "0", "time" : "2011-09-07 10:22:35", "timestamp" : "1315383755", "trace_id" : "372", "ts" : "2011-09-07 09:28:42" } 
+6
source share
2 answers

I assume this is an index issue. I bet that droppay has an index on: time, and some unsafe operations updated the base collection without updating the index.

Can you try restoring db and see if it improves.

Good luck.

+1
source

There are probably time values ​​that refer to an array of types.

You can do db.droppay.find({time: {$type : 4}}) to find such documents.

0
source

Source: https://habr.com/ru/post/901104/


All Articles