pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

<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="r7tjbnl" 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="dhbhnvl" 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="kkegqos" 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>

                          主站蜘蛛池模板: 济南网站建设_济南网站制作_济南网站设计_济南网站建设公司_富库网络旗下模易宝_模板建站 | 桑茶-七彩贝壳桑叶茶 长寿茶 | 污水提升器,污水提升泵,地下室排水,增压泵,雨水泵,智能供排水控制器-上海智流泵业有限公司 | 股指期货-期货开户-交易手续费佣金加1分-保证金低-期货公司排名靠前-万利信息开户 | 磨煤机配件-高铬辊套-高铬衬板-立磨辊套-盐山县宏润电力设备有限公司 | 安徽合肥格力空调专卖店_格力中央空调_格力空调总经销公司代理-皖格制冷设备 | 上海恒驭仪器有限公司-实验室平板硫化机-小型平板硫化机-全自动平板硫化机 | 品牌设计_VI设计_电影海报设计_包装设计_LOGO设计-Bacross新越品牌顾问 | 北京银联移动POS机办理_收银POS机_智能pos机_刷卡机_收银系统_个人POS机-谷骐科技【官网】 | 实战IT培训机构_IT培训班选大学生IT技术培训中心_中公优就业 | 聚合甘油__盐城市飞龙油脂有限公司 | 双效节能浓缩器-热回流提取浓缩机组-温州市利宏机械 | POM塑料_PBT材料「进口」聚甲醛POM杜邦原料、加纤PBT塑料报价格找利隆塑料 | 运动木地板厂家_体育木地板安装_篮球木地板选购_实木运动地板价格 | pbt头梳丝_牙刷丝_尼龙毛刷丝_PP塑料纤维合成毛丝定制厂_广州明旺 | 鑫铭东办公家具一站式定制采购-深圳办公家具厂家直销 | 雷蒙磨,雷蒙磨粉机,雷蒙磨机 - 巩义市大峪沟高峰机械厂 | 北京中创汇安科贸有限公司| 济南品牌包装设计公司_济南VI标志设计公司_山东锐尚文化传播 | 深圳侦探联系方式_深圳小三调查取证公司_深圳小三分离机构 | PC阳光板-PC耐力板-阳光板雨棚-耐力板雨棚,厂家定制[优尼科板材] | 潍坊青州古城旅游景点攻略_青州酒店美食推荐-青州旅游网 | 水压力传感器_数字压力传感器|佛山一众传感仪器有限公司|首页 | 钛板_钛管_钛棒_钛盘管-无锡市盛钛科技有限公司 | 禹城彩钢厂_钢结构板房_彩钢复合板-禹城泰瑞彩钢复合板加工厂 | 磷酸肌酸二钠盐,肌酐磷酰氯-沾化欣瑞康生物科技 | 体感VRAR全息沉浸式3D投影多媒体展厅展会游戏互动-万展互动 | 塑料撕碎机_编织袋撕碎机_废纸撕碎机_生活垃圾撕碎机_废铁破碎机_河南鑫世昌机械制造有限公司 | Q361F全焊接球阀,200X减压稳压阀,ZJHP气动单座调节阀-上海戎钛 | 偏心半球阀-电动偏心半球阀-调流调压阀-旋球阀-上欧阀门有限公司 | 纸布|钩编布|钩针布|纸草布-莱州佳源工艺纸布厂 | SMC-SMC电磁阀-日本SMC气缸-SMC气动元件展示网 | 不发火防静电金属骨料_无机磨石_水泥自流平_修补砂浆厂家「圣威特」 | 工业设计,人工智能,体验式3D展示的智能技术交流服务平台-纳金网 J.S.Bach 圣巴赫_高端背景音乐系统_官网 | 智能风向风速仪,风速告警仪,数字温湿仪,综合气象仪(气象五要素)-上海风云气象仪器有限公司 | 九州网址_专注于提供网址大全分享推广中文网站导航服务 | 成都装修公司-成都装修设计公司推荐-成都朗煜装饰公司 | 不锈钢反应釜,不锈钢反应釜厂家-价格-威海鑫泰化工机械有限公司 不干胶标签-不干胶贴纸-不干胶标签定制-不干胶标签印刷厂-弗雷曼纸业(苏州)有限公司 | 工业铝型材生产厂家_铝合金型材配件批发精加工定制厂商 - 上海岐易铝业 | 电脑刺绣_绣花厂家_绣花章仔_织唛厂家-[源欣刺绣]潮牌刺绣打版定制绣花加工厂家 | 下水道疏通_管道疏通_马桶疏通_附近疏通电话- 立刻通 |