How to make a MongoDB query sort on strings with -number postfix?

后端 未结 6 554
花落未央
花落未央 2021-01-04 01:04

I have a query:

ownUnnamedPages = Entries.find( { author : this.userId, title : {$regex: /^unnamed-/ }}, {sort: { title: 1 }}).fetch()

That

6条回答
  •  星月不相逢
    2021-01-04 01:15

    The mongo documentation said you can use Collation for this goal as @Eugene Kaurov said you can use

    .collation({locale: "en_US", numericOrdering: true})
    

    this is the official documentation: mongo ref

    and be aware that the accepted answer is not correct now

提交回复
热议问题