mongodb - Will aggregation pipeline use index for derived field? -


in aggregation pipeline have this:-

  {     "$project" => {       account_name_i: { "$tolower" => "$account_name" },     }   }    {     "$sort" => {       account_name_i: 1     }   } 

and have index { account_name: 1 }

my question $sort use index on account_name? if no, there other way can achieve in aggregation pipeline?

no. aggregation pipeline can use standard index on $match or $sort phase that's @ beginning of pipeline. rules using indexes aggregation pipelines described in detail in manual.

you aim sort on lower-case version of account_name_i, function case-insensitive sort. achieve index, store lower-case-normalized version of account_name_i in each document

{ "account_name_i" : "truman's haberdashery", "account_name_i_lc" : "truman's haberdashery" } 

and index normalized field ({ "account_name_i_lc" : 1 }).


Comments

Popular posts from this blog

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -