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

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

    <small id='5Js1J'></small><noframes id='5Js1J'>

      <bdo id='5Js1J'></bdo><ul id='5Js1J'></ul>

      <tfoot id='5Js1J'></tfoot>

      1. <legend id='5Js1J'><style id='5Js1J'><dir id='5Js1J'><q id='5Js1J'></q></dir></style></legend>

        如何通過 Promise 重用 mongodb 連接

        How to reuse mongodb connection through Promise(如何通過 Promise 重用 mongodb 連接)

        • <bdo id='DVVzK'></bdo><ul id='DVVzK'></ul>

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

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

                  本文介紹了如何通過 Promise 重用 mongodb 連接的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我想重用 MongoDB 連接.我知道 如何在 node.js 中重用 mongodb 連接我想使用 Promises 和 Mongo 驅動程序 v2 實現同樣的目標

                  I want to reuse MongoDB connection. I 'am aware of How to reuse mongodb connection in node.js I want to acheive the same using Promises and Mongo driver v2

                  目前我必須為每個請求連接到數據庫,這使得它變慢了.這是我的代碼

                  Currently I have to connect to db for every request which makes it slow. This is my code

                  "use strict"
                  var app = require('./utils/express')();
                  var mongodb = require('mongodb');
                  
                  var MongoClient = mongodb.MongoClient;
                  //Actually I 'am connecting to MongoLab
                  var url = 'mongodb://localhost/my-mongo';
                  
                  app.set('port', (process.env.PORT || 5000));
                  
                  app.listen(app.get('port'), function () {
                    console.log('ParkMe app is running on port', app.get('port'));
                  });
                  
                  
                  app.get('/location/create', function(req,res,next){
                    MongoClient.connect(url).then(function(db) {
                      return db.collection('parkme_parkingLots').find({}).toArray().then(function (docs) {
                        return docs;
                      });
                    });
                  });
                  

                  我想做這樣的事情:

                  "use strict"
                  var app = require('./utils/express')();
                  var mongodb = require('mongodb');
                  
                  var MongoClient = mongodb.MongoClient;
                  var url = 'mongodb://nidhind:1234@ds051635.mongolab.com:51635/my-mongo';
                  var db = MongoClient.connect(url).then(function(db) {
                      return db;
                  });
                  
                  app.set('port', (process.env.PORT || 5000));
                  
                  app.listen(app.get('port'), function () {
                    console.log('ParkMe app is running on port', app.get('port'));
                  });
                  
                  
                  app.get('/location/create', function(req,res,next){
                    db.collection('parkme_parkingLots').find({}).toArray().then(function (docs) {
                      return docs;
                    });
                  });
                  

                  推薦答案

                  你快到了,你的代碼只需要做幾處更改:

                  You're almost there, there are only a couple of changes in your code to be made:

                  "use strict"
                  var app = require('./utils/express')();
                  var mongodb = require('mongodb');
                  
                  var MongoClient = mongodb.MongoClient;
                  var url = 'mongodb://nidhind:1234@ds051635.mongolab.com:51635/my-mongo';
                  // no need to call then() yet
                  var connection = MongoClient.connect(url);
                  
                  app.set('port', (process.env.PORT || 5000));
                  
                  app.listen(app.get('port'), function() {
                    console.log('ParkMe app is running on port', app.get('port'));
                  });
                  
                  
                  app.get('/location/create', function(req, res, next) {
                    // the connection is opened once, use it at will
                    connection.then(function(db) {
                      db.collection('parkme_parkingLots').find({}).toArray().then(function(docs) {
                        return docs;
                      });
                    });
                  });
                  

                  這篇關于如何通過 Promise 重用 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 - 在彈出窗口中獲取標記的緯度和經度)
                  • <small id='yj0GP'></small><noframes id='yj0GP'>

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

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

                          2. 主站蜘蛛池模板: 日日摸夜夜添夜夜添精品视频 | 中文二区 | 91免费观看视频 | 特一级毛片 | 99精品网 | 成人午夜视频在线观看 | 999精品视频 | 国产探花 | 一区二区三区免费在线观看 | 日韩精品一区二区三区在线播放 | 精品国产一区二区三区性色av | 一级片av | 日韩伦理一区二区 | 超碰3 | 日韩av电影在线观看 | 国产一在线 | 自拍视频国产 | 91精品国产乱码麻豆白嫩 | 亚洲精品99 | 中文字幕免费视频 | 国产亚洲精品久久久久久豆腐 | 成人av免费 | 日韩在线观看 | 国产成人免费视频 | 日本在线播放一区二区 | 日本免费一区二区三区视频 | 国产精品99999 | 国产一二区在线 | 色资源站 | 欧美精品在欧美一区二区 | www.啪啪.com| 中文在线一区 | 国产精品久久久久一区二区三区 | 国产高清精品一区二区三区 | 欧美日本韩国一区二区 | 欧美日韩电影一区二区 | 噜啊噜在线 | 国产精品一区久久久 | 久久高清 | 91精品久久久 | 丝袜 亚洲 另类 欧美 综合 |