I have this kind of collection :
"File"
{
"_id" : { "$oid" : "4f730e3bb8be296910000180"}
, "Name" : "File1.jpg"
, "Folders" : [
{ "F_id" : { "$oid" : "4f72f503b8be296d78000166"} , "Ord" : 1}
, { "F_id" : { "$oid" : "4f730eedb8be296e78000180"} , "Ord" : 3}
]
}
{
"_id" : { "$oid" : "4f730e3ab8be296978000181"}
, "Name" : "File2.jpg"
, "Folders" : [
{ "F_id" : { "$oid" : "4f72f503b8be296d78000166"} , "Ord" : 2}
, { "F_id" : { "$oid" : "4f730eedb8be296e78000180"} , "Ord" : 2}
, { "F_id" : { "$oid" : "4f730eedb8be296e78000132"} , "Ord" : 1}
]
}
{
"_id" : { "$oid" : "4f730e38b8be296e78000182"}
, "Name" : "File3.jpg"
, "Folders" : [
{ "F_id" : { "$oid" : "4f72f503b8be296d78000166"} , "Ord" : 3}
, { "F_id" : { "$oid" : "4f730eedb8be296e78000180"} , "Ord" : 1}
]
}
"Folders" can contains a lot of more elements, and reflects in which Folder "F_id" the file is available, and at what order it take place "Ord" in this folder.
Then I would like to simply get all the Files available in one Folder in the correct Order.
But when I do something like :
File.find( {"Folders.F_id":{"$oid":4f72f503b8be296d78000166} } ).sort({"Folders.$.Ord":1}) ;
I can't get the correct Order I expected !
Any idea ?? Should I use Map reduce for that ? How ??
Thanks !