Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB : query result size greater than collection size

Tags:

mongodb

I'm analyzing a MongoDB data source to check its quality. I'm wondering if every document contains the attribute time: so I used this two command

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

How can I have more elements with a given field than the elements contained in whole collection ? What's going wrong ? I'm unable to find the mistake. If it's necessary I can post 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 structure of the document entry:

{
  "_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"
}
like image 592
LoSciamano Avatar asked Nov 09 '11 10:11

LoSciamano


People also ask

Is there a way to query array fields with size greater than some specified value?

Yes, you can do that using $expr operator along with the $size operator. Here, we are using $expr operator to filter out all those documents which has size greater than or equal to 4.

Why are MongoDB data files large in size?

This number is larger than dataSize because it includes yet-unused space (in data extents) and space vacated by deleted or moved documents within extents. The storageSize does not decrease as you remove or shrink documents.


1 Answers

My guess is that is an issue with the index. I bet that droppay has an index on :time, and some unsafe operation updated the underlying collection without updating the index.

Can you try repairing the db, and see if that makes it better.

Good luck.

like image 186
Jonathan Avatar answered Nov 15 '22 06:11

Jonathan