Return latest record from subdocument in Mongodb

前端 未结 3 1637
-上瘾入骨i
-上瘾入骨i 2021-01-24 10:45

Let\'s say i want to return the latest inserted document from the subdocument. I want to be able to return the second record within the tags array w/ the _id of

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-24 11:33

    I needed to find the last entry of subdocuments and I managed to make it to work with the $slice projection operator: mondodb.com > $slice (projection)

    db.modules.find({_id:'ui', 'svn_branches.branch':'Rocky'}, 
                    { 'svn_branches.tags': {$slice:-1} } )
    

    I had only one level, if this doesn't work, please let me know.

提交回复
热议问题