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

    <tfoot id='oGqKL'></tfoot>

    1. <small id='oGqKL'></small><noframes id='oGqKL'>

      <legend id='oGqKL'><style id='oGqKL'><dir id='oGqKL'><q id='oGqKL'></q></dir></style></legend>

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

        <bdo id='oGqKL'></bdo><ul id='oGqKL'></ul>

      如何計算貓鼬中具有一個不同字段的記錄?

      How to count records with one distinct field in mongoose?(如何計算貓鼬中具有一個不同字段的記錄?)

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

                <tbody id='WDbxR'></tbody>

            1. <i id='WDbxR'><tr id='WDbxR'><dt id='WDbxR'><q id='WDbxR'><span id='WDbxR'><b id='WDbxR'><form id='WDbxR'><ins id='WDbxR'></ins><ul id='WDbxR'></ul><sub id='WDbxR'></sub></form><legend id='WDbxR'></legend><bdo id='WDbxR'><pre id='WDbxR'><center id='WDbxR'></center></pre></bdo></b><th id='WDbxR'></th></span></q></dt></tr></i><div class="4cw0saa" id='WDbxR'><tfoot id='WDbxR'></tfoot><dl id='WDbxR'><fieldset id='WDbxR'></fieldset></dl></div>

                <bdo id='WDbxR'></bdo><ul id='WDbxR'></ul>
                <tfoot id='WDbxR'></tfoot><legend id='WDbxR'><style id='WDbxR'><dir id='WDbxR'><q id='WDbxR'></q></dir></style></legend>
              • 本文介紹了如何計算貓鼬中具有一個不同字段的記錄?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                在為 nodejs 探索 mongoose 時,我遇到了需要知道我的集合中用戶數量的問題:

                While exploring mongoose for nodejs I ran into the problem of needing to know the amount of user in my collection:

                我的收藏有記錄,每條記錄都有一個用戶.我想知道唯一(不同)用戶的數量.

                My collection has records, each record has a user. I want to know the amount of unique (different) users.

                我怎樣才能用貓鼬做到這一點?

                How can I do this with mongoose?

                數據庫增長很快,有沒有辦法從數據庫中取回數字而不是獲取所有不同的記錄并計算它們?

                The database is growing quite fast, is there anyway to get the number back from the DB instead of getting all the distinct records and counting them?

                推薦答案

                這是一個替代答案,因為當我嘗試 Reddest 的 Mongoose 3.1.2 方法時遇到異常(這對我來說似乎是 Mongoose 中的一個錯誤,因為 Reddest 的方法應該沒事).

                Here's an alternative answer as I get an exception when I try Reddest's approach with Mongoose 3.1.2 (which seems like a bug in Mongoose to me as Reddest's approach should be fine).

                您可以在集合的模型上調用 distinct 方法,指定該集合的用戶標識字段的名稱:

                You can call the distinct method on your collection's model, specifying the name of the user-identifying field of that collection:

                Record.distinct('user_id').exec(function (err, user_ids) {
                    console.log('The number of unique users is: %d', user_ids.length);
                });
                

                或者,如果您想從查找中鏈接 distinct 調用,請在 distinct 調用中包含回調(這對我有用):

                Or if you want to chain the distinct call from a find, include the callback in the distinct call (this did work for me):

                Record.find().distinct('user_id', function (err, user_ids) { ... });
                

                更新

                如果您只想要計數而不獲取值,請在鏈中添加 count() 調用:

                If you just want the count without getting the values, stick a count() call in the chain:

                Record.distinct('user_id').count().exec(function (err, count) {
                    console.log('The number of unique users is: %d', count);
                });
                

                注意:這在最新的 Mongoose 代碼 (3.5.2) 中不起作用.

                NOTE: this doesn't work in the latest Mongoose code (3.5.2).

                這篇關于如何計算貓鼬中具有一個不同字段的記錄?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 - 在彈出窗口中獲取標記的緯度和經度)
              • <tfoot id='zjUjS'></tfoot>

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

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

                        • 主站蜘蛛池模板: 医院专用门厂家报价-医用病房门尺寸大全-抗菌木门品牌推荐 | 淘趣英语网 - 在线英语学习,零基础英语学习网站 | 塑料瓶罐_食品塑料瓶_保健品塑料瓶_调味品塑料瓶–东莞市富慷塑料制品有限公司 | 河南橡胶接头厂家,河南波纹补偿器厂家,河南可曲挠橡胶软连接,河南套筒补偿器厂家-河南正大阀门 | 台式低速离心机-脱泡离心机-菌种摇床-常州市万丰仪器制造有限公司 | 七维官网-水性工业漆_轨道交通涂料_钢结构漆 | 盛源真空泵|空压机-浙江盛源空压机制造有限公司-【盛源官网】 | RTO换向阀_VOC高温阀门_加热炉切断阀_双偏心软密封蝶阀_煤气蝶阀_提升阀-湖北霍科德阀门有限公司 | IHDW_TOSOKU_NEMICON_EHDW系列电子手轮,HC1系列电子手轮-上海莆林电子设备有限公司 | 儿童乐园|游乐场|淘气堡招商加盟|室内儿童游乐园配套设备|生产厂家|开心哈乐儿童乐园 | 国际学校_国际学校哪个好_国际课程学校-国际学校择校网 | 粉末冶金注射成型厂家|MIM厂家|粉末冶金齿轮|MIM零件-深圳市新泰兴精密科技 | 哈希余氯测定仪,分光光度计,ph在线监测仪,浊度测定仪,试剂-上海京灿精密机械有限公司 | 储能预警-储能消防系统-电池舱自动灭火装置-四川千页科技股份有限公司官网 | 济南拼接屏_山东液晶拼接屏_济南LED显示屏—维康国际官网 | 真空粉体取样阀,电动楔式闸阀,电动针型阀-耐苛尔(上海)自动化仪表有限公司 | 并网柜,汇流箱,电控设备,中高低压开关柜,电气电力成套设备,PLC控制设备订制厂家,江苏昌伟业新能源科技有限公司 | 贝朗斯动力商城(BRCPOWER.COM) - 买叉车蓄电池上贝朗斯商城,价格更超值,品质有保障! | 富森高压水枪-柴油驱动-养殖场高压清洗机-山东龙腾环保科技有限公司 | 拉力机-拉力试验机-万能试验机-电子拉力机-拉伸试验机-剥离强度试验机-苏州皖仪实验仪器有限公司 | 高压负荷开关-苏州雷尔沃电器有限公司 | 污水处理设备维修_污水处理工程改造_机械格栅_过滤设备_气浮设备_刮吸泥机_污泥浓缩罐_污水处理设备_污水处理工程-北京龙泉新禹科技有限公司 | 道达尔润滑油-食品级润滑油-道达尔导热油-合成导热油,深圳道达尔代理商合-深圳浩方正大官网 | 耐酸泵,耐腐蚀真空泵,耐酸真空泵-淄博华舜耐腐蚀真空泵有限公司 精密模具-双色注塑模具加工-深圳铭洋宇通 | 济南律师,济南法律咨询,山东法律顾问-山东沃德律师事务所 | 硫酸亚铁-聚合硫酸铁-除氟除磷剂-复合碳源-污水处理药剂厂家—长隆科技 | 干洗加盟网-洗衣店品牌排行-干洗设备价格-干洗连锁加盟指南 | 富森高压水枪-柴油驱动-养殖场高压清洗机-山东龙腾环保科技有限公司 | 铣刨料沥青破碎机-沥青再生料设备-RAP热再生混合料破碎筛分设备 -江苏锡宝重工 | 高精度电阻回路测试仪-回路直流电阻测试仪-武汉特高压电力科技有限公司 | 油冷式_微型_TDY电动滚筒_外装_外置式电动滚筒厂家-淄博秉泓机械有限公司 | 上海恒驭仪器有限公司-实验室平板硫化机-小型平板硫化机-全自动平板硫化机 | 福州甲醛检测-福建室内空气检测_环境检测_水质检测-福建中凯检测技术有限公司 | 渣土车电机,太阳能跟踪器电机,蜗轮蜗杆减速电机厂家-淄博传强电机 | 耐高温风管_耐高温软管_食品级软管_吸尘管_钢丝软管_卫生级软管_塑料波纹管-东莞市鑫翔宇软管有限公司 | 警用|治安|保安|不锈钢岗亭-售货亭价格-垃圾分类亭-移动厕所厂家-苏州灿宇建材 | 空压机商城|空气压缩机|空压机配件-压缩机网旗下商城 | 丹佛斯压力传感器,WISE温度传感器,WISE压力开关,丹佛斯温度开关-上海力笙工业设备有限公司 | 深圳希玛林顺潮眼科医院(官网)│深圳眼科医院│医保定点│香港希玛林顺潮眼科中心连锁品牌 | 贴片电容代理-三星电容-村田电容-风华电容-国巨电容-深圳市昂洋科技有限公司 | 岩棉切条机厂家_玻璃棉裁条机_水泥基保温板设备-廊坊鹏恒机械 |