LoSciamano
LoSciamano

Reputation: 1119

MongoDB : query result size greater than collection size

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"
}

Upvotes: 6

Views: 1849

Answers (2)

Jonathan
Jonathan

Reputation: 16359

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.

Upvotes: 1

lig
lig

Reputation: 3910

There are probably time values that are of type array.

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

Upvotes: 0

Related Questions