MongoDB - Client Count vs PHP Driver Count

399 views
Skip to first unread message

Noth86

unread,
Apr 7, 2011, 6:47:39 AM4/7/11
to mongodb-user
Hi all,
i have strange problem with my php DRIVER.
I have create a collection with multi value field:

{
_id: 1
keyword:
{
list: [ 1,2,3,4,5,6 ],
proc: 1
}
}

I try to execute this query:
Mongo Client query: db.items.count( { 'keyword.list': 3 } )
Mongo Client result: 8029

Php Driver query: $mongo->selectDB('db1')->selectCollection('items')-
>count( array( 'keyword.list' => 3 ) );
Php Driver result: 46

Why this difference?

Nat

unread,
Apr 7, 2011, 6:51:04 AM4/7/11
to mongod...@googlegroups.com
It sounds like you use different database. Are you sure you use database db1 for both mongo client and php?
--
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.

Noth86

unread,
Apr 7, 2011, 6:56:18 AM4/7/11
to mongodb-user
Sure.
If I run the count without parameters, both return 7257084 rows.

Nat

unread,
Apr 7, 2011, 7:00:50 AM4/7/11
to mongod...@googlegroups.com
- Why don't you try to find() instead of count() to see what missing items in php are? Could you list some?
- can you show db.items.stats()?
-----Original Message-----
From: Noth86 <l.da...@gmail.com>

esagod

unread,
Apr 7, 2011, 10:25:58 AM4/7/11
to mongodb-user
Nat,
this is db.items.stats() result:

> db.items.stats()
{
"ns" : "db1.items",
"count" : 7257084,
"size" : 10612484056,
"avgObjSize" : 1462.3620252983153,
"storageSize" : 11907873536,
"numExtents" : 36,
"nindexes" : 14,
"lastExtentSize" : 1991168256,
"paddingFactor" : 1.0099999999170273,
"flags" : 1,
"totalIndexSize" : 7737619584,
"indexSizes" : {
"_id_" : 243205056,
"id_domain_1" : 413238208,
"id_feed_1" : 400917440,
"id_site_1" : 381559744,
"url_1" : 1451230144,
"crc_1" : 306054080,
"keyword.proc_1" : 272532416,
"keyword.list_1" : 1697366976,
"image.proc_1" : 269648832,
"enabled_1" : 309552064,
"check_1" : 265028544,
"solr_1" : 405275584,
"date_1" : 348611520,
"image.url_1" : 973398976
},
"ok" : 1
}

I have try to use find() instead of count() but i have always the same
results.

[PHP]
<?php
$count = $mongo->selectDB('db1')->selectCollection('items')-
>find( array( 'keyword.list' => 3 ), array( '_id' => 1, 'keyword.list'
=> 1 ) )->timeout(-1);
foreach( $count as $item )
print_r( $item );
$count->count() . "\n";
?>

Total record is 48.
Row result sample:

Array
(
[_id] => 52927115
[keyword] => Array
(
[list] => Array
(
[0] => 3
[1] => 214
[2] => 2003
[3] => 2016
[4] => 2019
[5] => 2020
)

)

)
Array
(
[_id] => 52927019
[keyword] => Array
(
[list] => Array
(
[0] => 3
[1] => 6
[2] => 1475
[3] => 1504
[4] => 36017
)

)

)
Array
(
[_id] => 52926931
[keyword] => Array
(
[list] => Array
(
[0] => 3
[1] => 144
[2] => 2366
)

)

)


[CLIENT]
> db.items.find( { 'keyword.list': 3 }, { 'keyword.list': 1} )

Total record is 8029.
Row result sample:
{ "_id" : 9358927, "keyword" : { "list" : [ 3, 263, 1475 ] } }
{ "_id" : 9358973, "keyword" : { "list" : [ 3, 1475, 1512 ] } }
{ "_id" : 9359208, "keyword" : { "list" : [ 3 ] } }
{ "_id" : 9359456, "keyword" : { "list" : [ 3, 12, 217, 231, 249,
2324, 2340 ] } }
{ "_id" : 9360295, "keyword" : { "list" : [ 3, 1197, 1216, 1340,
29952 ] } }
{ "_id" : 9360333, "keyword" : { "list" : [ 3, 20, 250, 933 ] } }
{ "_id" : 9360334, "keyword" : { "list" : [ 3, 1475 ] } }


I have try to execute the query with value 1475 and the result row is
the same: 265634

Nat

unread,
Apr 7, 2011, 10:31:18 AM4/7/11
to mongod...@googlegroups.com
Can you try to rebuild indices and see whether the problem goes away?

Davide Pilato

unread,
Apr 7, 2011, 11:27:14 AM4/7/11
to mongod...@googlegroups.com, Nat
I have rebuild indices and the count result is equal.

Why this difference form shell and driver?


-------------------------------------------------------------
Davide Pilato
Cellulare: +39.347.30.65.210
Skype: davide_pilato

Mail: davide...@gmail.com
--
Le informazioni, il contenuto e gli allegati di questo messaggio sono da considerarsi solo per uso dei destinatari sopra indicati.
Qualunque utilizzazione o copia di questa comunicazione è rigorosamente vietata.
Questo messaggio costituisce una comunicazione riservata, se lo avesse ricevuto per errore, Le saremmo grati se lo distruggesse e ce ne comunicasse, via e-mail, l'errata ricezione all'indirizzo davide...@gmail.com.



2011/4/7 Nat <nat....@gmail.com>

Nat

unread,
Apr 7, 2011, 11:35:27 AM4/7/11
to mongodb-user
It could probably use a different plan and one of them may use a
corrupted index.

On Apr 7, 11:27 pm, Davide Pilato <davide.pil...@gmail.com> wrote:
> I have rebuild indices and the count result is equal.
>
> Why this difference form shell and driver?
>
> -------------------------------------------------------------
> *Davide Pilato*
> *Cellulare*: +39.347.30.65.210
> *Skype*: davide_pilato
> *Mail*: davide.pil...@gmail.com
> --
> Le informazioni, il contenuto e gli allegati di questo messaggio sono da
> considerarsi solo per uso dei destinatari sopra indicati.
> Qualunque utilizzazione o copia di questa comunicazione è rigorosamente
> vietata.
> Questo messaggio costituisce una comunicazione riservata, se lo avesse
> ricevuto per errore, Le saremmo grati se lo distruggesse e ce ne
> comunicasse, via e-mail, l'errata ricezione all'indirizzo
> davide.pil...@gmail.com.
>
> 2011/4/7 Nat <nat.lu...@gmail.com>

Davide Pilato

unread,
Apr 7, 2011, 11:36:41 AM4/7/11
to mongod...@googlegroups.com, Nat
Thank you!

-------------------------------------------------------------
Davide Pilato
Cellulare: +39.347.30.65.210
Skype: davide_pilato

Mail: davide...@gmail.com
--
Le informazioni, il contenuto e gli allegati di questo messaggio sono da considerarsi solo per uso dei destinatari sopra indicati.
Qualunque utilizzazione o copia di questa comunicazione è rigorosamente vietata.
Questo messaggio costituisce una comunicazione riservata, se lo avesse ricevuto per errore, Le saremmo grati se lo distruggesse e ce ne comunicasse, via e-mail, l'errata ricezione all'indirizzo davide...@gmail.com.



2011/4/7 Nat <nat....@gmail.com>
Reply all
Reply to author
Forward
0 new messages