$ lookup

时间:2018-10-26 22:38:38

标签: arrays json mongodb aggregation-framework aggregate

此查询返回一个结果时遇到问题:

{
    "_id" : ObjectId("5bd22f28f77cfb1f6ce503ca"),
    "search" : "flarize",
    "name" : "flarize",
    "color" : 0,
    "profil" : "",
    "banner" : "",
    "desc" : "",
    "date" : 1540501286109,
    "friend" : [
            [        
                    {
                            "_id" : ObjectId("5bd22f28f77cfb1f6ce503ca"),
                            "search" : "flarize",
                            "name" : "flarize",
                            "email" : "flarize.b73@gmail.com",
                            "password" : "$2a$10$eYeOtEkEUyD7TFkjKvhZOuSSpvBolkL17TrPHuoHhOT8JrsQR0UKW",
                            "color" : 0,
                            "profil" : "",
                            "banner" : "",
                            "desc" : "",
                            "date" : 1540501286109,
                            "friend" : [
                                    {
                                            "id" : ObjectId("5bd22f28f77cfb1f6ce503ca"),
                                            "date" : 1540572026419
                                    },
                                    {
                                            "id" : ObjectId("5bd19a92da24674fdabd26b6"),
                                            "date" : 1540572026419
                                    }
                            ],
                            "groupes" : [ ]
                    }
            ]
    ]
}

但这并不是我真正想要的,我希望隐藏这些字段:friend.password,friend.email以及friend.groups和friend.friend的结果限制为10。我不知道如何我可以解决这个问题。我的要求:

db.users.aggregate(
    {$match:
        {search:"flarize"}
    },
    {$lookup:
        {from:"users", 
         localField:"friend.id", 
         foreignField:"_id", 
         as:"friend"
    }},
    {$project:
        { search: 1, 
         name: 1, 
         profil: 1, 
         banner: 1, 
         color: 1, 
         date: 1, 
         desc: 1, 
         friend: [{$slice:["$friend", 0, 10]}]
    }
}).pretty();

一个用户文档:

{
    "_id" : ObjectId("5bd22f28f77cfb1f6ce503ca"),
    "search" : "flarize",
    "name" : "flarize",
    "email" : "theo.ba73@gmail.com",
    "password" : "$2a$10$eYeOtEkEUyD7TFkjKvhZOuSSpvBolkL17TrPHuoHhOT8JrsQR0UKW",
    "color" : 0,
    "profil" : "",
    "banner" : "",
    "desc" : "",
    "date" : 1540501286109,
    "friend" : [
            {
                    "id" : ObjectId("5bd22f28f77cfb1f6ce503ca"),
                    "date" : 1540572026419
            },
            {
                    "id" : ObjectId("5bd19a92da24674fdabd26b6"),
                    "date" : 1540572026419
            }
    ],
    "groupes" : [ ]
 }

谢谢您的帮助。

1 个答案:

答案 0 :(得分:1)

您可以尝试以下汇总

#Flutter Wrapper
-keep class io.flutter.app.** { *; }
-keep class io.flutter.plugin.**  { *; }
-keep class io.flutter.util.**  { *; }
-keep class io.flutter.view.**  { *; }
-keep class io.flutter.**  { *; }
-keep class io.flutter.plugins.**  { *; }
-keep class com.google.firebase.** { *; }