用于在mongodb中返回文档的单个属性的查询

时间:2017-10-02 16:09:21

标签: mongodb mongodb-query subdocument

[ "_id" : ObjectId("59d1f4d0539f772aacf90f61"), 
    "user_id" : 1222.0, 
    "user_name" : "jadenn", 
    "email" : "jdkdkdjjjjjjjjjjjjjjjjjjjh@j.com", 
    "phone" : 333333333.0, 
    "image_ref" : "static/image/123IMG_20170917_232813.jpg", 
    "stories" : [
        {
            "title" : "accident", 
            "description" : "kjsbskns", 
            "longitude" : 19.2, 
            "latitude" : 81.4, 
            "location" : "isl", 
            "date" : 12.0, 
            "reactions" : [
                {
                    "type" : "seen", 
                    "date" : "1234", 
                    "user_id" : 123.0
                }, 
                {
                    "type" : "seen", 
                    "date" : "1234", 
                    "user_id" : 123.0
                }
            ], 
            "comments" : [
                {
                    "comment" : "djksnjknfkjguye", 
                    "date" : 123.0, 
                    "user_id" : 123.0
                }, 
                {
                    "comment" : "this is the accident case ", 
                    "date" : 123.0, 
                    "user_id" : 123.0
                }
            ], 
            "reports" : [
                {
                    "description" : "uye", 
                    "date" : 123.0, 
                    "user_id" : 1232321.0
                }
            ], 
            "catagory_name" : [
                {
                    "type" : "uye"
                }
            ]
        }
    ]
}

这是我的文档,我想要一个只返回故事列表的查询。不是完整的用户文档。我搜索但找不到解决方案。每个解决方案都通过应用"其中条件为MYSQL"] 1

来返回完整的文档

1 个答案:

答案 0 :(得分:0)

您需要在文档中按stories键投影,如下所示:

db.youCollection.find({}, {stories:1, _id:0})