That's a start, but I could use a bit more information. If by "embedded documents" you are referring to derived nesting, your post doesn't address best practices when I need to change the number for a particular source and have it reflected across the document database. It's sounding like I will need to update all documents containing that source, if it's derived. I could simply store the source key name in each, but how would I arbitrarily order their output by the value that key points to in the sources collection?
If, for instance, I have a sources collection:
{"_id" : ObjectId( "4a92af2db3d09cb83d985f6f") , "source_one" : 1, "metadata" : "blah blah"}
{"_id" : ObjectId( "4a92af2db3d09cb83d985f70") , "source_two" : 10, "metadata" : "and so on"}
{"_id" : ObjectId( "4a92af2db3d09cb83d985f71") , "source_three" : 20, "metadata" : "who cares"}
And a document collection:
{"_id" : ObjectId( "9cb83d985f6f4a92af2db3d0") , "important_value" : "foo", "source" : "source_two"}
{"_id" : ObjectId( "9cb83d985f6f4a92af2db3d1") , "important_value" : "bar", "source" : "source_one"}
{"_id" : ObjectId( "9cb83d985f6f4a92af2db3d2") , "important_value" : "baz", "source" : "source_three"}
{"_id" : ObjectId( "9cb83d985f6f4a92af2db3d3") , "important_value" : "wibble", "source" : "source_one"}
I would like to be able to write a query that returns important values in source-sorted order
{ "important_value" : "baz" }
{ "important_value" : "foo" }
{ "important_value" : "bar" }
{ "important_value" : "wibble"}
is group() what I'm looking for?
-Andy