0

I am currently having trouble getting the value of _id when I use either groupBy or distinct. The values of groupBy/distinct replaces the value of _id.

how do I use the library properly to achieve this?

here is the library https://github.com/jenssegers/laravel-mongodb

or if you can show me how to use PHP mongo's aggregate to correctly replicate the groupBy or Distinct behavior, that would be much appreciated. :)

Thank you very much!

Neil Lunn
  • 148,042
  • 36
  • 346
  • 317
  • share some code, that you might've written so far, to show in which direction, and how much, you've worked so far – sunbabaphu Jul 22 '14 at 03:41
  • It's actually just a simple groupBy() that I need. Nothing complicated. – ShotgunSparkle Jul 22 '14 at 03:41
  • I just settled with using the library's `raw` method and doing the native MongoCollection::aggregate from the callback, as seen here http://php.net/manual/en/mongocollection.aggregate.php there is also http://php.net/manual/en/mongocollection.group.php which returns everything. unadvisable though. – ShotgunSparkle Jul 22 '14 at 10:05

1 Answers1

0

IDs aren't relevant in these cases, as the results do not correspond to individual rows, but aggregations thereof. If you wanted an ID to be returned, you can't use aggregate functions.

Perhaps the premise of your query is not set up correctly. What is it you are trying to achieve?

Ali Raza
  • 243
  • 4
  • 11