How are null values in a MongoDB index sorted?

前端 未结 2 1048
情话喂你
情话喂你 2021-01-17 16:55

I want to sort my index in a specific way (-1, 1) and want to make sure that null values are at the top of the index. How can I ensure this?

2条回答
  •  粉色の甜心
    2021-01-17 17:38

    You have said" I just want to basically have an 'if one with null exists take it, else take one without' by one query", how about db.collection.find().sort().limit(1) ?

提交回复
热议问题