久久久久久久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>

                        • 主站蜘蛛池模板: 国产乱码久久久久久一区二区 | 亚洲一区二区三区四区五区中文 | 中国黄色毛片视频 | 性欧美hd| 亚洲 成人 在线 | 中文字幕在线观看一区二区 | 99亚洲综合| 一区二区三区日韩 | 国产精品一级在线观看 | 日韩免费视频 | 精品国产18久久久久久二百 | 天天躁人人躁人人躁狂躁 | 欧美日韩中文字幕在线 | 日韩成人在线网站 | 97久久精品午夜一区二区 | 国产精品日产欧美久久久久 | 日韩欧美三级在线 | 国产天天操| 免费一级片 | 四虎影院在线观看av | 国产精品成人国产乱 | 欧美极品视频在线观看 | 亚洲一区二区电影在线观看 | julia中文字幕久久一区二区 | 99综合| 成人精品一区二区三区四区 | 久久激情视频 | 久久中文高清 | 国产一级一级国产 | 色噜噜亚洲男人的天堂 | 特一级毛片 | www国产亚洲精品久久网站 | 不卡的av一区 | 在线观看免费高清av | 久草视频在线播放 | 欧美成视频 | 日日摸日日添日日躁av | 女同av亚洲女人天堂 | 在线色网| 99re在线视频 | 91精品国产91久久综合桃花 |