How to Find the matched record in mongodb?

前端 未结 2 509
一个人的身影
一个人的身影 2021-01-13 10:06

I have a record in my collection and I want to fetch the details of the person whose id is 1. But I am getting the details for 2times instead of 1.

    db.m         


        
2条回答
  •  滥情空心
    2021-01-13 10:45

    person is an array. If you want to get first element of this array you should use $slice

    db.mycollection.findOne({"person.id":1},{"person":{$slice:[0,1]},"_id":0})
    

提交回复
热议问题