Mongodb: sort documents by array objects

前端 未结 4 470
遇见更好的自我
遇见更好的自我 2021-01-03 23:40

I would like to return the documents in an order sorted by which holds the lowest foo.bar value (which are array objects).

I can do db.collection

4条回答
  •  别那么骄傲
    2021-01-04 00:20

    There is no direct way to do this in mongo. You would need to use map/reduce to retrieve the min val in each array and then sort by that min value

提交回复
热议问题