Questions tagged [node-mongodb-native]

The MongoDB Native Node.js driver is an officially supported driver providing a native asynchronous Node.js interface to MongoDB. It can be used on its own, but it also serves as the basis of several object mapping libraries, such as Mongoose.

The MongoDB Native Node.js driver is an officially supported driver written in pure JavaScript to provide a native asynchronous Node.js interface to MongoDB. The driver is optimized for simplicity. It can be used on its own, but it also serves as the basis of several object mapping libraries, such as Mongoose ODM.

Installing/upgrading

The easiest way to install the driver is to use npm:

$ npm install mongodb

Documentation

3.0 Driver

2.2 Driver

Related links

482 questions
7
votes
1 answer

Getting the old and new version of the document when updating it

For every operation my application does on MongoDB I want to have the old and new version of the document so I can emit an event with both version: { type: 'UPDATE', before: documentBeforeUpdate, after: documentAfterUpdate } The way I do this…
despairblue
  • 347
  • 2
  • 8
7
votes
0 answers

How to use setOnInsert to place created/updated field in mongodb?

I'm using a nodejs client to loop over input and create an array of values that will be handed off to the bulkWrite operation: var updateVal = { sku: item.sku, name: item.name, updatedAt: new Date()}; var insertVal = { sku: item.sku, name:…
pulkitsinghal
  • 3,855
  • 13
  • 45
  • 84
7
votes
2 answers

node.js - MongoError: Can't canonicalize query: BadValue bad order array [2]

I have a database with the following document structure: { "_id" : ObjectId("520bea012ab230549e749cff"), "Day" : 1, "Time" : 54, "State" : "Vermont", "Airport" : "BTV", "Temperature" : 39, "Humidity" : 57, "Wind…
Dennis
  • 487
  • 5
  • 15
7
votes
1 answer

Use single connection pool for cluster vs multiple connection pool for each child process in mongodb-native NodeJS

I'm implementing a nodejs server which is using mongodb as database and mongodb-native library to connect it. Further, I'm using clustering to enhance the server performances. So there are two possible ways to use mongodb-native driver's connection…
gihanchanuka
  • 4,783
  • 2
  • 32
  • 32
7
votes
3 answers

Error: connect EADDRNOTAVAIL while processing big async loop

I am experiencing a very strange problem. I am importing some big xml-files and store them into mongoDB. The algorythm is a typical async loop: doLoop = function( it, callback_loop ) { if( it < no_of_items ) { storeToMongo( ...,…
heinob
  • 19,127
  • 5
  • 41
  • 61
7
votes
1 answer

node-mongodb-native MongoClient unexpectedly closing connections

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:…
Nate Stewart
  • 73
  • 1
  • 4
7
votes
1 answer

MongoDB connections keep increasing

I keep hitting my connection limit, but http traffic has remained consistent. I used MMS to profile my mongod process and saw that the number of connections keeps rising: I'm using the mongoskin wrapper for Node.js (Express). I have a piece of…
Jonathan Drake
  • 270
  • 1
  • 4
  • 13
6
votes
0 answers

How do I optimize working with large datasets in MongoDB

We have multiple collections of about 10,000 documents (this will become increasingly more in the future) that are generated in node.js, and need to be stored/queried/filtered/projected multiple times for which we have a mongodb aggregation…
Redsandro
  • 11,060
  • 13
  • 76
  • 106
6
votes
1 answer

Node.JS + mongo: .find().each() stopping after first batch

This has me stumped. I have a standalone (command-line executed) node script, whose purpose is to iterate through all the documents in a large collection (several hundred thousand of them), and for each document, perform a few calculations, run a…
DanM
  • 7,037
  • 11
  • 51
  • 86
6
votes
1 answer

Cannot infer query fields to set error on insert

I'm trying to achieve a "getOrCreate" behavior using "findAndModify". I'm working in nodejs using the native driver. I have: var matches = db.collection("matches"); matches.findAndModify({ //query users: { $all: […
Pipe
  • 2,379
  • 2
  • 19
  • 33
6
votes
1 answer

MongoError: driver is incompatible with this server version

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…
Katie
  • 45,622
  • 19
  • 93
  • 125
6
votes
1 answer

Alternatives to MongoDB cursor.toArray() in node.js

I am currently using MongoDB cursor's toArray() function to convert the database results into an array: run = true; count = 0; var start = process.hrtime(); db.collection.find({}, {limit: 2000}).toArray(function(err, docs){ var diff =…
KMK
  • 1,439
  • 5
  • 21
  • 39
6
votes
1 answer

Using the find method on a MongoDB collection with Monk

I am working through a MEAN stack tutorial. It contains the following code as a route in index.js. The name of my Mongo collection is brandcollection. /* GET Brand Complaints page. */ router.get('/brands', function(req, res) { var…
jdw
  • 3,755
  • 3
  • 17
  • 16
6
votes
2 answers

How to reuse mongodb connection in node.js

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…
nickleefly
  • 3,733
  • 1
  • 29
  • 31
6
votes
1 answer

How to format the result of a mongodb find query?

i have a collection that is storing data in this format : { _id: ObjectId("51b9be6dbbdeef1e5f008cca"), name: 'sfdsfsdfsdfsdfsd' details: { varA: { created: "2013-06-13T12:43:25.853Z", validity:…
Michael
  • 2,436
  • 1
  • 36
  • 57
1 2
3
32 33