node-mongodb-native

How to reuse mongodb connection in node.js

ぐ巨炮叔叔 提交于 2019-11-28 10:22:38
I'm using node-mongodb-native driver with mongodb to write a website. I have a question about how to open mongodb connection once, then use it in collection name users in user.js and collection name posts in comment.js I want to open db connection in db.js then to insert / save data for users and posts collection Currently code,my db.js var Db = require('mongodb').Db, Connection = require('mongodb').Connection, Server = require('mongodb').Server; module.exports = new Db( 'blog', new Server('localhost', Connection.DEFAULT_PORT, {auto_reconnect: true}) ); I used db.js in user.js as follow var

Handling MongoDB disconnect/reconnects from Node

戏子无情 提交于 2019-11-27 21:29:52
问题 When my MongoDB connection is idle for a few minutes, the next request ends in error. From the mongo command line client, it looks like this: > db.users.find() Sat Jan 12 23:42:35 Socket recv() errno:54 Connection reset by peer 107.22.25.25:47207 Sat Jan 12 23:42:35 SocketException: remote: 107.22.25.25:47207 error: 9001 socket exception [1] server [107.22.25.25:47207] Sat Jan 12 23:42:35 DBClientCursor::init call() failed Sat Jan 12 23:42:35 query failed : chowology.users {} to: ds047207

runCommand equivalent for nodejs-native-mongodb

你说的曾经没有我的故事 提交于 2019-11-27 17:04:03
问题 I'm trying to utilize MongoDB 2.4 experimental text search feature from within nodejs. The only problem is, native nodejs mongo drivers don't seem to support collection-level runCommand, as far as I can tell. The Mongo shell syntax looks like this: db.collection.runCommand( "text", { search : "Textvalue" } ); There is a db.command / db.executeDbCommand function it appears, but I don't know how to choose a collection and run the text command using it (if it is possible), as it needs to be on

How to reuse mongodb connection in node.js

谁说胖子不能爱 提交于 2019-11-27 03:37:30
问题 I'm using node-mongodb-native driver with mongodb to write a website. I have a question about how to open mongodb connection once, then use it in collection name users in user.js and collection name posts in comment.js I want to open db connection in db.js then to insert / save data for users and posts collection Currently code,my db.js var Db = require('mongodb').Db, Connection = require('mongodb').Connection, Server = require('mongodb').Server; module.exports = new Db( 'blog', new Server(

How can I promisify the MongoDB native Javascript driver using bluebird?

守給你的承諾、 提交于 2019-11-26 20:24:59
I'd like to use the MongoDB native JS driver with bluebird promises . How can I use Promise.promisifyAll() on this library? Esailija The 2.0 branch documentation contains a better promisification guide https://github.com/petkaantonov/bluebird/blob/master/API.md#promisification It actually has mongodb example which is much simpler: var Promise = require("bluebird"); var MongoDB = require("mongodb"); Promise.promisifyAll(MongoDB); Dmitry Minkovsky When using Promise.promisifyAll() , it helps to identify a target prototype if your target object must be instantiated. In case of the MongoDB JS

Fail to connect Mongoose to Atlas

空扰寡人 提交于 2019-11-26 16:18:16
问题 I'm always connecting to the "admin" DB, which is a fixed bug. Using Mongoose 5.0.6 MongoDb 3.6 and trying to connect to Atlas. My question, what driver Mongoose 5.0.6 depend on? How can I find out when Mongoose will have that fix? On a different direction, is there a way to connect with MongoDB then use this connection with Mongoose? Cheers 回答1: Basically you should try connecting with your url link, and specify the DB name on the mongoose connect method so if your cluster link is: mongodb

How can I promisify the MongoDB native Javascript driver using bluebird?

久未见 提交于 2019-11-26 07:35:27
问题 I\'d like to use the MongoDB native JS driver with bluebird promises. How can I use Promise.promisifyAll() on this library? 回答1: The 2.0 branch documentation contains a better promisification guide https://github.com/petkaantonov/bluebird/blob/master/API.md#promisification It actually has mongodb example which is much simpler: var Promise = require("bluebird"); var MongoDB = require("mongodb"); Promise.promisifyAll(MongoDB); 回答2: When using Promise.promisifyAll() , it helps to identify a