Thursday 15 March 2012

Count too slow in MongoDB with PHP -


I am trying to check my code, but with the count lines this code works very slowly How can I customize this code? Is there anyway to count?

  $ find = $ conn_stok-> Different ("isbn"); ($ I = 0; $ i & lt; = 25; $ i ++) for {$ isbn = $ find [$ i]; $ Countit = $ conn_kit- & gt; Find (array ('isbn' => $ isbn)) - & gt; Count (); If ($ countit & gt; 0) {echo "ok 
"; } And {echo "error"
"; }}

It seems that you have to do a simple count (*) group In the old SQL speaking MongoDB you will use the aggregation framework to do the databases in your code instead of working for you.

The aggregation pipeline will look like this:

  db.collection.aggregate ({$ group: {_ id: "$ isbn", count: {$ sum} : 1}}}   

I let you translate it into PHP if you need help, so many examples are available.

No comments:

Post a Comment