Quantcast
Channel: Active questions tagged mongodb-atlas - Stack Overflow
Viewing all articles
Browse latest Browse all 280

sorting behavior and sorting sequence for mongodb

$
0
0

Does MongoDB use a different sort sequence order when sorting within a $search operation compared to a normal sort operation?

case 1:

db.collection.aggregate([{    $search: {      index: "default_multi_sort",      compound: {        must: [          {            in: {              path: "_id",              value: [               ObjectId("636cf2849d8e183db53aafca"),               ObjectId("636cf2849d8e183db53aafcf"),               ObjectId("636cf2849d8e183db53aafcd"),               ObjectId("636cf2849d8e183db53aafce"),              ],            },          },        ],      },      sort: {        name: 1,      },    },  }], {            collation: {                locale: "en",                numericOrdering: true            }        })

case 2:

db.collection.aggregate([  {    $match:      {        _id: {          $in: [            ObjectId("636cf2849d8e183db53aafca"),            ObjectId("636cf2849d8e183db53aafcf"),            ObjectId("636cf2849d8e183db53aafcd"),            ObjectId("636cf2849d8e183db53aafce"),          ],        },      },  },  {    $sort: {      name: 1,    },  },], {  collation: {    locale: "en",    numericOrdering: true  }});

In the first case, I receive numbers followed by alphabets, while in the second case, I receive a special character, then numbers, and finally alphabets. If this is true, how can I make them behave the same way?


Viewing all articles
Browse latest Browse all 280

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>