node-mongodb-native

MongoError: driver is incompatible with this server version

北战南征 提交于 2019-12-07 03:58:50
问题 I've just installed Mongo, Node, etc. and when I try to update the database via my nodejs server, I get this error: MongoError: driver is incompatible with this server version Here are the versions I have: Node v0.12.2 (latest is v0.12.3) Express v4.12.4 (latest is v4.12.4) Mongodb v3.0.3 (latest is v3.0.3) Mongodb Node.js Driver v2.0.33 (latest is v2.0.33) Mongoskin v1.3.23 (latest is v1.3.23) I have the latest versions of everything, and I've searched the node mongodb driver git to find out

node-mongodb-native MongoClient unexpectedly closing connections

筅森魡賤 提交于 2019-12-07 00:22:08
问题 I've been searching a lot for unexpectedly closed connections in mongodb but can only find questions from people who WANT their connections to close. I am using node-mongodb-native to connect to a db, but I keep getting seemingly random "Error: connection closed" messages. If I manually retry the request (browser refresh) the request works. Any idea what is causing this? Is there some simple option that will help? I'm getting my db handle using: MongoClient.connect(connection_string, { auto

How to query date range on the MongoDB collection where the ISO date is stored in string field?

邮差的信 提交于 2019-12-06 19:56:47
问题 Scenario : Consider I am having a collection called MyCollection , with following data: { "_id" : 'MyUniqueID_01' "CreatedTime" : "2013-12-01T14:35:00Z", "LastModifiedTime" : "2013-12-01T13:25:00Z" } Now I want to query the MongoDB database where the above mentioned kind of data is in huge number of documents. And my query is based on date range i.e. using $gt , $gte , $lt & $lte So my query may be something like: db.MyCollection.find({ 'CreatedTime': {$gt: '2013-05-25T09:29:40.572Z'}})

Handle lost connection to mongo db from nodejs

末鹿安然 提交于 2019-12-05 22:08:12
问题 I'm trying to get "connection lost" or something similar when connection lost between nodejs and mongodb server. I use native driver and has following code var mongo = require('mongodb'); var server = new mongo.Server('host', 'port', { auto_reconnect: true, socketOptions: { keepAlive: 10, connectTimeoutMS: 1000, socketTimeoutMS: 0 } }); var db = new mongo.Db( 'dbname', server, { w: 1, wtimeout: 1000, numberOfRetries: 100, auto_reconnect: true } ); db.on('close', function () { console.log(

Node Mongo Native - how to tell when a cursor is exhausted?

萝らか妹 提交于 2019-12-05 18:05:58
The documentation for the node-mongo-native collection.find() function says that it creates a cursor object which lazily returns the matching documents. Furthermore: The basic operation on a cursor is the nextObject method that fetches the next matching document from the database. The convenience methods each and toArray call nextObject until the cursor is exhausted. Unfortunately, the documentation provides no indication of how to tell when the cursor is actually exhausted. You could use the "toArray" method and use the standard array interface (e.g. the "length" method) but this solution is

What does an example MongoDB error look like on the NodeJS native driver?

泪湿孤枕 提交于 2019-12-05 09:56:10
I can't seem to find any examples of MongoDB error objects in their documentation or on the internet. What does an example MongoDB error object look like? I'd like to "handle" the error and/or reformat it for my own purposes, depending on what the error is. As of MongoDB 2.4.8 with the mongodb 1.3.23 driver, they look like this: { "name":"MongoError", "err":"E11000 duplicate key error index: test.test.$country_1 dup key: { : \"XYZ\" }", "code":11000, "n":0, "connectionId":10706, "ok":1 } MongoError objects With newer versions of the node-mongodb-driver (>= 2) things are a little bit different.

node-mongodb-native MongoClient unexpectedly closing connections

喜欢而已 提交于 2019-12-05 04:51:31
I've been searching a lot for unexpectedly closed connections in mongodb but can only find questions from people who WANT their connections to close. I am using node-mongodb-native to connect to a db, but I keep getting seemingly random "Error: connection closed" messages. If I manually retry the request (browser refresh) the request works. Any idea what is causing this? Is there some simple option that will help? I'm getting my db handle using: MongoClient.connect(connection_string, { auto_reconnect: true }, function (err, db) { //server code/routes in here } I was looking through https:/

mongodb nodejs each vs toArray

妖精的绣舞 提交于 2019-12-05 01:47:52
问题 I've had a quick look around and not found anything that's satisfied me with an answer but basically I've started to use node.js with express and mongodb to create a webapi rather than the usual .Net MVC Web API route. One thing I've noted though is in order to return a collection of results I'm doing it in a rather bulky way, or that's how it feels at least. app.get('/property', function (req, res) { var propArray = []; MongoClient.connect(settings.connection, function (err, db) { if (err)

What aggregation cursor methods are supported by Nodejs drivers?

泪湿孤枕 提交于 2019-12-05 01:24:24
问题 As you know from 2.6 on Mongodb aggregate() operation returns a cursor, however the behavior is a bit different than the normal cursor which returns from a find() . I am using native mongodb nodejs driver, and could not find a proper documentation on available aggregate cursor methods. For example, one cannot run a count() on an aggregation cursor however there are two methods such cursor.objsLeftInBatch() and cursor.itcount() n mongo shell. I could not find any of them in the source code of

Passing reference to DB into routes is not working for my Node / Express project

血红的双手。 提交于 2019-12-04 15:41:27
I am using node + express to create a simple REST API, and am trying to separate out routing logic from db logic. I am having a problem getting access to the DB from the routes. Here is my server.js code: var express = require('express') , path = require('path') , http = require('http') , mongo = require('mongodb'); // Configure Express app var app = express(); app.configure(function () { app.set('port', process.env.PORT || 3000); app.use(express.logger('dev')); /* 'default', 'short', 'tiny', 'dev' */ app.use(express.bodyParser()), app.use(express.static(path.join(__dirname, 'public'))); }); /