久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<i id='RqRun'><tr id='RqRun'><dt id='RqRun'><q id='RqRun'><span id='RqRun'><b id='RqRun'><form id='RqRun'><ins id='RqRun'></ins><ul id='RqRun'></ul><sub id='RqRun'></sub></form><legend id='RqRun'></legend><bdo id='RqRun'><pre id='RqRun'><center id='RqRun'></center></pre></bdo></b><th id='RqRun'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='RqRun'><tfoot id='RqRun'></tfoot><dl id='RqRun'><fieldset id='RqRun'></fieldset></dl></div>

    1. <legend id='RqRun'><style id='RqRun'><dir id='RqRun'><q id='RqRun'></q></dir></style></legend>
      • <bdo id='RqRun'></bdo><ul id='RqRun'></ul>

      <small id='RqRun'></small><noframes id='RqRun'>

      <tfoot id='RqRun'></tfoot>

      查詢依賴于 mongodb 中其他文檔值的文檔

      query documents that depend on values of other documents in mongodb(查詢依賴于 mongodb 中其他文檔值的文檔)

      • <small id='WFpok'></small><noframes id='WFpok'>

        <tfoot id='WFpok'></tfoot>
        <legend id='WFpok'><style id='WFpok'><dir id='WFpok'><q id='WFpok'></q></dir></style></legend>
          <tbody id='WFpok'></tbody>
          <bdo id='WFpok'></bdo><ul id='WFpok'></ul>
            • <i id='WFpok'><tr id='WFpok'><dt id='WFpok'><q id='WFpok'><span id='WFpok'><b id='WFpok'><form id='WFpok'><ins id='WFpok'></ins><ul id='WFpok'></ul><sub id='WFpok'></sub></form><legend id='WFpok'></legend><bdo id='WFpok'><pre id='WFpok'><center id='WFpok'></center></pre></bdo></b><th id='WFpok'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='WFpok'><tfoot id='WFpok'></tfoot><dl id='WFpok'><fieldset id='WFpok'></fieldset></dl></div>

                本文介紹了查詢依賴于 mongodb 中其他文檔值的文檔的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                想象下面的貓鼬模型:

                const UserSchema = Schema({
                  //_id: ObjectId,
                  //more fields,
                  blockedIds: [{
                    type: ObjectId,
                    ref: 'User'
                  }]
                })
                

                獲取與某個 _id 的用戶的阻塞 ID 不匹配的所有用戶的最有效方法是什么?

                What is the most efficient way to get all users that don't match the blockedIds of an user with a certain _id?

                一種天真的方法是執行兩個查詢:

                A naive way would be to to perform two queries:

                User.findById(id).then(user => {
                  return User.find({_id: {$nin: user.blockedIds}})
                })
                

                是否可以使用聚合框架和 $facets 在一個查詢中完成?

                Is it possible to use the aggregation framework and $facets to accomplish that in one query?

                推薦答案

                試試 non-correlated 來自 3.6 的子查詢,用于您的用例.

                Try non-correlated sub query from 3.6 for your use case.

                有點像

                User.aggregate(
                 [{$lookup:{
                   from: "users",
                   pipeline:[
                    {$match: {_id:mongoose.Types.ObjectId(id)}},
                    {$project: {_id:0,blockedIds:1}}
                   ],
                   as: "noncr"
                 }},
                 {$match:{
                   $expr:{
                     $not:[
                      {$in:[
                        $_id,
                        {$arrayElemAt:["$noncr.blockedIds",0]}
                      ]}
                    ]
                  }
                }},
                {$project:{noncr:0}}]
                )
                

                $lookup 為輸入 ID 拉入blockedIds",然后是 $match 過濾_id"不在blockedIds列表中的文檔.

                $lookup to pull in the "blockedIds" for input id followed by $match to filter the documents where "_id" is not in list of blockedIds.

                $expr 允許在 $match 階段使用聚合比較運算符.

                $expr allows use of aggregation comparison operators in $match stage.

                $arrayElemAt 從 $lookup 數組中獲取第一個元素.

                $arrayElemAt to fetch the first element from $lookup array.

                $in 將_id 與blockedIds 進行比較.

                $in to compare the _id against blockedIds.

                $project 排除以從最終響應中刪除noncr"字段.

                $project with exclusion to remove the "noncr" field from the final response.

                請注意,當您測試查詢時,在查找階段的from"屬性中使用集合名稱而不是模型或模式名稱.

                Please note when you test query use the collection name not model or schema name in "from" attribute of look up stage.

                這篇關于查詢依賴于 mongodb 中其他文檔值的文檔的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                Check if a polygon point is inside another in leaflet(檢查一個多邊形點是否在傳單中的另一個內部)
                Changing leaflet markercluster icon color, inheriting the rest of the default CSS properties(更改傳單標記群集圖標顏色,繼承其余默認 CSS 屬性)
                Trigger click on leaflet marker(觸發點擊傳單標記)
                How can I change the default loading tile color in LeafletJS?(如何更改 LeafletJS 中的默認加載磁貼顏色?)
                Adding Leaflet layer control to sidebar(將 Leaflet 圖層控件添加到側邊欄)
                Leaflet - get latitude and longitude of a marker inside a pop-up(Leaflet - 在彈出窗口中獲取標記的緯度和經度)
                  <bdo id='5IsLU'></bdo><ul id='5IsLU'></ul>
                  <tfoot id='5IsLU'></tfoot>
                  <i id='5IsLU'><tr id='5IsLU'><dt id='5IsLU'><q id='5IsLU'><span id='5IsLU'><b id='5IsLU'><form id='5IsLU'><ins id='5IsLU'></ins><ul id='5IsLU'></ul><sub id='5IsLU'></sub></form><legend id='5IsLU'></legend><bdo id='5IsLU'><pre id='5IsLU'><center id='5IsLU'></center></pre></bdo></b><th id='5IsLU'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='5IsLU'><tfoot id='5IsLU'></tfoot><dl id='5IsLU'><fieldset id='5IsLU'></fieldset></dl></div>

                        <tbody id='5IsLU'></tbody>
                      1. <small id='5IsLU'></small><noframes id='5IsLU'>

                        • <legend id='5IsLU'><style id='5IsLU'><dir id='5IsLU'><q id='5IsLU'></q></dir></style></legend>

                          主站蜘蛛池模板: 国产成人精品综合 | 亚洲精品久久久一区二区三区 | 日本在线观看网址 | 日韩欧美亚洲 | 久久精品一区 | 久久99网 | 999精品视频 | 羞羞在线视频 | 日韩一区二区三区视频在线观看 | 成人在线视频观看 | 欧美一区2区三区4区公司 | 美女久久视频 | 81精品国产乱码久久久久久 | 日韩av在线播 | 亚洲一区在线播放 | 免费影视在线观看 | 亚洲精品久久久久久下一站 | 日韩欧美一区二区三区免费观看 | 男人天堂国产 | 久久久久久亚洲精品不卡 | 成人免费看片 | 欧美一级二级视频 | 国产激情在线观看 | 精品国产欧美一区二区三区不卡 | 97caoporn国产免费人人 | 国产精品视频久久 | 国产精品久久久久久中文字 | 福利片在线看 | 日韩中文字幕在线观看 | 天天干夜夜| 亚洲 欧美 另类 日韩 | 国产精品久久久久久久久久三级 | 亚洲不卡一 | 亚洲精品视频观看 | 污片在线观看 | 精品久久99 | 亚洲a网 | 欧美一区二区三区在线视频 | 国产精品资源在线 | 国产精品视频一 | 国产精品国产a级 |