I have collection with the following structure:
{
...
TitleComposite: [
{
TitleType: "01",
TitleText "Title Important"
},
{
TitleType: "03",
TitleText: "Not so important"
}
]
...
}
What I want to do is to sort collection by TitleComposite.TitleText which has TitleType equal to "01".
So, only string "Title Important" will take part in sorting. I'm not sure is it possible and if yes, is it effective? I have quite large collection of documents (about 11 000 for now) and maybe creating of separate field for sorting purpose only is better?
UPD
@TrudBert, I tried what you advice and made the following request:
db.onix_feed.aggregate(
{$unwind: '$titleComposite'},
{$match:{'titleComposite.titleType':"01"}},
{$sort:{'titleCompostite.titleText':1}},
{$project: {"titleComposite.titleText":1, "_id": 0}}
)
But return result doesn't seem to be sorted by titleText:
{ "titleComposite" : { "titleText" : "Small Scale Mining" } }
{ "titleComposite" : { "titleText" : "Cane Sugar" } }
{ "titleComposite" : { "titleText" : "Microenterprises In Developing Countries" } }
{ "titleComposite" : { "titleText" : "The Development of Indian Silk" } }
{ "titleComposite" : { "titleText" : "Stoves for People" } }
....
titleCompostite.titleTextedited that