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
6
votes
1 answer

runCommand equivalent for nodejs-native-mongodb

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…
Glem
  • 449
  • 6
  • 16
6
votes
3 answers

how to enable debug on node.js and mongoDB native driver?

i use node.js and node-mongodb-native driver, with connection pooling. is there any way to enable debug for see what's happening, how many connections are active and when a connection is opened or closed? i would like to see something like: *…
Alessandro
  • 303
  • 4
  • 12
6
votes
2 answers

node.js mongodb how to connect to replicaset of mongo servers

I am using mongo and node.js in an application. The mongo database consists of two servers. In the example given in http://howtonode.org/express-mongodb, i can connect to one server using: ArticleProvider = function(host, port) { var database =…
Tuco
  • 712
  • 2
  • 8
  • 20
5
votes
3 answers

Mongodb update all the documents with unique id

I have collection with name products with almost 100k documents. I want to introduce a new key called secondaryKey with unique value uuid in all the documents. I do this using nodejs. Problem I am facing:- When I try the below…
abinas patra
  • 359
  • 3
  • 21
5
votes
1 answer

Multi-tenant MongoDB + mongo-native driver + connection pooling

We are trying to implement the strategy outlined in the following presentation (slides 13-18) using nodejs/mongo-native driver. https://www.slideshare.net/mongodb/securing-mongodb-to-serve-an-awsbased-multitenant-securityfanatic-saas-application In…
5
votes
1 answer

TypeError: Grid is not a constructor. Mongodb node driver

I am learning to use mongdb gridfs with nodejs driver. I got stuck on the very first step. var MongoClient = require('mongodb').MongoClient; var Grid = require("mongodb").Grid; MongoClient.connect("mongodb://localhost:27017/kkdb", function(err,…
Khurshid
  • 458
  • 1
  • 5
  • 20
5
votes
1 answer

MongoError: no primary found in replicaset (Mongoose replaces external IP addresses on gcloud with internal addresses)

(cross-posting https://github.com/Automattic/mongoose/issues/4834) This is the latest version of mongodb - 3.4.0 (mongo:latest from docker) and I have installed a mongo cluster on google compute engine. Each mongo server has an external and an…
5
votes
1 answer

Mongo connection stream closes unexpectedly in NodeJS application

I have a NodeJS application (using the node-mongodb-native driver version 2.1) which does the following: Opens a connection to MongoDB. Queries a collection (batchSize is set to 1000). This query returns about 1,300,000 documents which I have…
Dave Cooper
  • 10,494
  • 4
  • 30
  • 50
5
votes
1 answer

How to count number of groups that meet a certain condition with MongoDB aggregate framework?

I have a MongoDB aggregation operation that uses a couple of groups: { $group: { "_id": { "vid": "$visitor_id", "pid":"$project.id" } } } { $group: { "_id": "$_id.vid", "count": { $sum: 1} } } that returns the following data: { "results": [ …
5
votes
1 answer

MongoError: key $ must not start with '$' when store JSON object generated by xml2js module

Everyone, MongoDB db.version() is 3.0.5 mongodb package.json shows 2.0.42 version xml2js package.json shows 0.4.9 version I have already googled the error, and read through all the existing questions and none seem to match my circumstances…
Raf
  • 7,505
  • 1
  • 42
  • 59
5
votes
1 answer

Changing mongo database

I want to query a collection in my replica set using the native 2.0 mongodb driver for node. I can connect and authenticated against the admin database but how do I switch databases to query the collection I'm interested in? var mongodb =…
Chris Seymour
  • 83,387
  • 30
  • 160
  • 202
5
votes
2 answers

ReferenceError: require is not defined in MongoDB shell

I try to connect MongoDB from Mongo client on windows command (Window 8.1). When I use require() in javascript, I have error as below. Does any one has same issue? Did I miss any require related npm installation? How can't MongoDB shell find require…
Scott Lee
  • 51
  • 1
  • 1
  • 5
5
votes
1 answer

Add caching to node.js MongoDB API?

My node.js API runs some expensive "group" queries against MongoDB using for example: app.get('/group/:collection', function(req, res) { [...] db.collection("indicators").group(keys, conds, { value : 0 } [...] What are some fairly…
dani
  • 4,880
  • 8
  • 55
  • 95
5
votes
1 answer

Can't use $text with String

This code dumped to exception self.staticVars.Model .find({shortAddress: {$text : { $search: data.text }}, _town: data._town},{limit: 10}) .populate('_street _district') .sort({house: 1}) …
Mike Bazhenov
  • 128
  • 1
  • 9
5
votes
1 answer

MongoDb date format

I was doing bulk insert into MongoDB using NodeJs (native -driver). I have date field in the data. Is there anyway to store the date field as Date rather than String? I have date in dd/mm/yyyy format. In current scenario I attain the result by…
Okky
  • 10,338
  • 15
  • 75
  • 122