MongoDB uses unicode, instead of the coding for a certain local language, to sort data in this language (i.e. Chinese). Together with esProc, MongoDB can realize sorting in local language conveniently (i.e. sort Chinese according to Chinese phonetic alphabet). The following will teach you the method in detail by taking Chinese as an example.
person - a collection in MongoDB - stores names and genders as follows:
> db.person.find()
{ "_id" : ObjectId("544e4e070f03ad39eb2bf498"), "name" : "宋江", "gender" : "ç·"}
{ "_id" : ObjectId("544e4e070f03ad39eb2bf499"), "name" : "æŽé€µ", "gender" : "ç·"}
{ "_id" : ObjectId("544e4e070f03ad39eb2bf49a"), "name" : "å´ç¨", "gender" : "ç·"}
{ "_id" : ObjectId("544e4e070f03ad39eb2bf49b"), "name" : "æ™ç›–", "gender" : "ç·"}
{ "_id" : ObjectId("544e4e070f03ad39eb2bf49c"), "name" : "å…¬å™èƒœ", "gender" : "ç·" }
{ "_id" : ObjectId("544e4e070f03ad39eb2bf49d"), "name" : "é²æ™ºæ·±", "gender" : "ç·" }
{ "_id" : ObjectId("544e4e070f03ad39eb2bf49e"), "name" : "æ¦æ¾", "gender" : "ç·"}
{ "_id" : ObjectId("544e4e070f03ad39eb2bf49f"), "name" : "阮å°äºŒ", "gender" : "ç·" }
{ "_id" : ObjectId("544e4e070f03ad39eb2bf4a0"), "name" : "æ¨å¿—", "gender" : "ç·"}
{ "_id" : ObjectId("544e4e070f03ad39eb2bf4a1"), "name" : "å™äºŒå¨˜", "gender" : "女" }
{ "_id" : ObjectId("544e4e070f03ad39eb2bf4a2"), "name" : "扈三娘", "gender" : "女" }
{ "_id" : ObjectId("544e4e080f03ad39eb2bf4a3"), "name" : "燕é’", "gender" : "ç·"}
…
Sort the data using MongoDB’s sort function rather than the Chinese phonetic alphabet:
> db.person.find({},{"name":1,"gender":1,"_id":0}).sort({"name":1})
{ "name" : "å…¬å™èƒœ", "gender" : "ç·" }
{ "name" : "å´ç¨", "gender" : "ç·" }
{ "name" : "å™äºŒå¨˜", "gender" : "女" }
{ "name" : "宋江", "gender" : "ç·" }
{ "name" : "扈三娘", "gender" : "女" }
{ "name" : "æ™ç›–", "gender" : "ç·" }
{ "name" : "æŽé€µ", "gender" : "ç·" }
{ "name" : "æ¨å¿—", "gender" : "ç·" }
{ "name" : "æ¦æ¾", "gender" : "ç·" }
{ "name" : "燕é’", "gender" : "ç·" }
{ "name" : "阮å°äºŒ", "gender" : "ç·" }
{ "name" : "é²æ™ºæ·±", "gender" : "ç·" }
…
The esProc script helping with MongoDB computation is as follows: