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="oausu0i" 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="ommmi2g" 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="s0qgyco" 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>

                        • 主站蜘蛛池模板: 缓蚀除垢剂_循环水阻垢剂_反渗透锅炉阻垢剂_有机硫化物-郑州威大水处理材料有限公司 | 产业规划_产业园区规划-产业投资选址及规划招商托管一体化服务商-中机院产业园区规划网 | 建大仁科-温湿度变送器|温湿度传感器|温湿度记录仪_厂家_价格-山东仁科 | 污水提升器,污水提升泵,污水提升装置-德国泽德(zehnder)水泵系统有限公司 | 智成电子深圳tdk一级代理-提供TDK电容电感贴片蜂鸣器磁芯lambda电源代理经销,TDK代理商有哪些TDK一级代理商排名查询。-深圳tdk一级代理 | 粉丝机械,粉丝烘干机,粉丝生产线-招远市远东粉丝机械有限公司 | 开锐教育-学历提升-职称评定-职业资格培训-积分入户 | 视觉检测设备_自动化检测设备_CCD视觉检测机_外观缺陷检测-瑞智光电 | 翻斗式矿车|固定式矿车|曲轨侧卸式矿车|梭式矿车|矿车配件-山东卓力矿车生产厂家 | 低温等离子清洗机(双气路进口)-嘉润万丰| 济南货架定做_仓储货架生产厂_重型货架厂_仓库货架批发_济南启力仓储设备有限公司 | 玉米加工设备,玉米深加工机械,玉米糁加工设备.玉米脱皮制糁机 华豫万通粮机 | 氢氧化钙设备_厂家-淄博工贸有限公司| 量子管通环-自清洗过滤器-全自动反冲洗过滤器-北京罗伦过滤技术集团有限公司 | 机构创新组合设计实验台_液压实验台_气动实训台-戴育教仪厂 | 雪花制冰机(实验室雪花制冰机)百科 | 上海律师事务所_上海刑事律师免费咨询平台-煊宏律师事务所 | PVC地板|PVC塑胶地板|PVC地板厂家|地板胶|防静电地板-无锡腾方装饰材料有限公司-咨询热线:4008-798-128 | 耐磨焊丝,堆焊焊丝,耐磨药芯焊丝,碳化钨焊丝-北京耐默公司 | 企业彩铃制作_移动、联通、电信集团彩铃上传开通_彩铃定制_商务彩铃管理平台-集团彩铃网 | 新疆散热器,新疆暖气片,新疆电锅炉,光耀暖通公司 | 上海公众号开发-公众号代运营公司-做公众号的公司企业服务商-咏熠软件 | 杭州画室_十大画室_白墙画室_杭州美术培训_国美附中培训_附中考前培训_升学率高的画室_美术中考集训美术高考集训基地 | 冷凝锅炉_燃气锅炉_工业燃气锅炉改造厂家-北京科诺锅炉 | 南昌旅行社_南昌国际旅行社_南昌国旅在线| 润滑脂-高温润滑脂-轴承润滑脂-食品级润滑油-索科润滑油脂厂家 | 牛皮纸|牛卡纸|进口牛皮纸|食品级牛皮纸|牛皮纸厂家-伽立实业 | 涡街流量计_LUGB智能管道式高温防爆蒸汽温压补偿计量表-江苏凯铭仪表有限公司 | 石磨面粉机|石磨面粉机械|石磨面粉机组|石磨面粉成套设备-河南成立粮油机械有限公司 | 防水试验机_防水测试设备_防水试验装置_淋雨试验箱-广州岳信试验设备有限公司 | LZ-373测厚仪-华瑞VOC气体检测仪-个人有毒气体检测仪-厂家-深圳市深博瑞仪器仪表有限公司 | 便携式谷丙转氨酶检测仪|华图生物科技百科 | 深圳宣传片制作_产品视频制作_深圳3D动画制作公司_深圳短视频拍摄-深圳市西典映画传媒有限公司 | 模具ERP_模具管理系统_模具mes_模具进度管理_东莞市精纬软件有限公司 | 道达尔润滑油-食品级润滑油-道达尔导热油-合成导热油,深圳道达尔代理商合-深圳浩方正大官网 | 注塑_注塑加工_注塑模具_塑胶模具_注塑加工厂家_深圳环科 | 连续油炸机,全自动油炸机,花生米油炸机-烟台茂源食品机械制造有限公司 | 不锈钢发酵罐_水果酒发酵罐_谷物发酵罐_山东誉诚不锈钢制品有限公司 | 河南道路标志牌_交通路标牌_交通标志牌厂家-郑州路畅交通 | 合肥白癜风医院_[治疗白癜风]哪家好_合肥北大白癜风医院 | 软文发布-新闻发布推广平台-代写文章-网络广告营销-自助发稿公司媒介星 |