Order by referenced document's field

10 views
Skip to first unread message

D

unread,
Jun 16, 2014, 3:01:47 PM6/16/14
to rogue...@googlegroups.com
Hi!
Is there a way to order a query by a referenced document's field?


Thanks

Jason Liszka

unread,
Jun 16, 2014, 4:05:19 PM6/16/14
to rogue...@googlegroups.com
Hi, can you give an example? Do you mean ordering by a field of a document referenced by a foreign key? If so, no, mongo does not allow that, since it has no notion of server-side joins.

Regards,
Jason


--
You received this message because you are subscribed to the Google Groups "rogue-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rogue-users...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

D

unread,
Jun 16, 2014, 4:21:14 PM6/16/14
to rogue...@googlegroups.com
Yes, that's what I meant :(
So no luck? 
Do I have to query for all the results and then manually sort and limit? 

Jason Liszka

unread,
Jun 16, 2014, 4:39:22 PM6/16/14
to rogue...@googlegroups.com
No, unfortunately. You have to do it in 2 separate queries and sort in memory.

Alternatively, you could denormalize some of the data that lives on the foreign records onto the records you want to sort.
Reply all
Reply to author
Forward
0 new messages