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

    <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="qwawimqqmiuu" 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="qwawimqqmiuu" 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="qwawimqqmiuu" 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>

                        • 主站蜘蛛池模板: 国产视频在线观看一区二区三区 | 精品视频在线免费观看 | 成人在线小视频 | 成人精品免费视频 | a在线视频| 国产日韩欧美在线一区 | 国产美女久久久 | 免费精品| 成人欧美一区二区三区黑人孕妇 | 国产一区二区三区四区五区加勒比 | 亚洲劲爆av | 日日夜夜91 | 综合久久av | 欧洲精品码一区二区三区免费看 | 无人区国产成人久久三区 | 中文字幕91 | 欧美乱操 | 日韩一区二区在线播放 | 久久久久国产一区二区三区不卡 | 91久久精品一区二区二区 | 欧美一级在线观看 | 国产伦精品一区二区三区高清 | 欧美日韩视频 | 精品日韩 | 天天色天天色 | 日韩三级在线 | 欧美日韩国产一区二区三区 | 久久久久久久久淑女av国产精品 | 久久久91精品国产一区二区三区 | 中文字幕在线免费视频 | 欧美激情精品久久久久久变态 | 色婷婷精品久久二区二区蜜臂av | 国产一区久久久 | 欧美精品一区二区三区在线 | 亚洲视频中文字幕 | 久草综合在线 | 91久久精品 | 在线看一区二区三区 | 99国产精品99久久久久久 | 国产成人99久久亚洲综合精品 | 亚洲免费网站 |