Strange behaviour with $exists and $type

5 views
Skip to first unread message

Andrea Spacca

unread,
Aug 27, 2010, 2:53:02 PM8/27/10
to mongodb-user
Hello,

I've a collection I use for storing aggregated historical datas coming
from the online system application.
The aggregation for every document is done on three steps of "unique
keys signature", according to the granularity of the reports I need to
produce. The documents are not finally aggregated due to the needed
output, because it can vary on to many variables. In order to produce
the output I make on-fly mapreduce choosing which kind of granularity
access in the query part.

I choose this solution after a while of performance tests, preferring
direct discarding of documents by querying and then applying the
mapreduce to the remaining. (If there's is a smarter/better way to do
that, please, let me know :))


The problem is in querying part.
That's a sample shell that simulates what I ecounter:
[shell]
use test
db.testcollection.ensureIndex({date: -1, country_code: 1, user_id: 1},
{unique: 1, background: 1});
db.testcollection.insert({ date: new Date("27/08/2010"), tot_visit:
100});
db.testcollection.insert({ date: new Date("27/08/2010"), country_code:
"IT", tot_visit: 77});
db.testcollection.insert({ date: new Date("27/08/2010"), country_code:
"ES", tot_visit: 23});
db.testcollection.insert({ date: new Date("27/08/2010"), country_code:
"ES", user_id: "and...@spacca.org", tot_visit: 11});
db.testcollection.insert({ date: new Date("27/08/2010"), country_code:
"ES", user_id: "andrea...@gmail.com", tot_visit: 5});
db.testcollection.insert({ date: new Date("27/08/2010"), country_code:
"ES", user_id: "andrea...@progloedizioni.com", tot_visit: 7});

db.testcollection.find({date: new Date("27/08/2010")}).count(); // 6
[OK]
db.testcollection.find({date: new Date("27/08/2010"), country_code:
{$exists: true}}).count(); // 5 [OK]
db.testcollection.find({date: new Date("27/08/2010"), country_code:
{$exists: false}}).count(); // 1 [OK]
db.testcollection.find({date: new Date("27/08/2010"), country_code:
{$type: 10}}).count(); // 1 [OK]
db.testcollection.find({date: new Date("27/08/2010"), country_code:
{$exists: true}, user_id: {$exists: true}}).count(); // 3 [OK]
db.testcollection.find({date: new Date("27/08/2010"), country_code:
{$exists: true}, user_id: {$exists: false}}).count(); // 2 [OK]
db.testcollection.find({date: new Date("27/08/2010"), country_code:
{$exists: true}, user_id: {$type: 10}}).count(); // 0 [??]
[/shell]



ps: the test was made on a three shard enviroment

Eliot Horowitz

unread,
Aug 31, 2010, 4:39:58 PM8/31/10
to mongod...@googlegroups.com
Can you try this in tomorrow's nightly?
I think we may have fixed this.
If that doesn't work - could you open a jira case?


--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.


Andrea Spacca

unread,
Sep 4, 2010, 1:46:57 PM9/4/10
to mongodb-user
Sorry, I've noticed your reply just now.

I tested against 1.7.0 today's nightly and 1.6.2: on debian lenny and
macosx 1.6.4 server the first, and just lenny the latter.

still the same issue, i'm going to open a jira case


On 31 Ago, 22:39, Eliot Horowitz <eliothorow...@gmail.com> wrote:
> Can you try this in tomorrow's nightly?
> I think we may have fixed this.
> If that doesn't work - could you open a jira case?
>
> > "ES", user_id: "andrea.spa...@gmail.com", tot_visit: 5});
> > db.testcollection.insert({ date: new Date("27/08/2010"), country_code:
> > "ES", user_id: "andrea.spa...@progloedizioni.com", tot_visit: 7});
>
> > db.testcollection.find({date: new Date("27/08/2010")}).count(); // 6
> > [OK]
> > db.testcollection.find({date: new Date("27/08/2010"), country_code:
> > {$exists: true}}).count(); // 5 [OK]
> > db.testcollection.find({date: new Date("27/08/2010"), country_code:
> > {$exists: false}}).count(); // 1 [OK]
> > db.testcollection.find({date: new Date("27/08/2010"), country_code:
> > {$type: 10}}).count(); // 1 [OK]
> > db.testcollection.find({date: new Date("27/08/2010"), country_code:
> > {$exists: true}, user_id: {$exists: true}}).count(); // 3 [OK]
> > db.testcollection.find({date: new Date("27/08/2010"), country_code:
> > {$exists: true}, user_id: {$exists: false}}).count(); // 2 [OK]
> > db.testcollection.find({date: new Date("27/08/2010"), country_code:
> > {$exists: true}, user_id: {$type: 10}}).count(); // 0 [??]
> > [/shell]
>
> > ps: the test was made on a three shard enviroment
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "mongodb-user" group.
> > To post to this group, send email to mongod...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > mongodb-user...@googlegroups.com<mongodb-user%2Bunsubscribe@google groups.com>
> > .
Reply all
Reply to author
Forward
0 new messages