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
4
votes
2 answers

Why isn't the MongoClient in my Node.js script finishing?

I have a one-shot Node script that makes some changes to a MongoDB database on MongoLab. However, once it finishes, it never exits the event loop (I always have to ctrl+C it), no matter how much db.close() and db.logout() calling I do. What's…
Stuart P. Bentley
  • 10,195
  • 10
  • 55
  • 84
4
votes
1 answer

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

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…
maerics
  • 151,642
  • 46
  • 269
  • 291
4
votes
1 answer

Mongodb Gridfs Reduce image size

I am working on a facebook like application using node.js and mongodb. I have been able to successfully upload image files to GridFS and retrieve them back using the awesome examples of the node-mongodb-native driver wiki. The maximum use of images…
user1583920
  • 227
  • 4
  • 11
3
votes
1 answer

Closing MongoClient connection on exit when using MongoDB Native driver?

Should the MongoClient connection be closed every time the server shuts down? I have seen the following code snippet and wanted to know if this is actually valid and should be done or if it's completely unnecessary to perform a closing on exit: //…
thelearner
  • 1,440
  • 3
  • 27
  • 58
3
votes
5 answers

How to list all indexes of Mongo Collection with MongoDB Node native?

Well I wanna know how I can fetch all indexes from a specific collection of mongodb. I trying with listIndexes, indexes and indexInformation, but these methods only give me empty values(array and object), but if I execute…
Olaf Erlandsen
  • 5,817
  • 9
  • 41
  • 73
3
votes
0 answers

How to verify mongoDB options set on connection level

Is there a way to verify options / settings that are set on the connection level? For example we set the following options: repository.options.w = 'majority'; repository.options.j = true; repository.options.readConcern = { level: 'linearizable'…
Robin F.
  • 1,137
  • 11
  • 19
3
votes
1 answer

Group mongodb collection and output the result as a single object

Is there a way to group a collection which looks like [ {_id: "5bd258a7877e74059b6b65b2", year: 2017, title: "One"}, {_id: "5bd258a7877e74059b6b65b3", year: 2017, title: "Two"}, {_id: "5bd258a7877e74059b6b65b4", year: 2018, title: "Three"}, …
kyrsquir
  • 51
  • 6
3
votes
1 answer

mongodb findOneAndUpdate get only updated fields

I am using mongodb to insert and update some documents in some collection. When I update a document, I want to get the modified fields only. I can get the complete new document (including the modified fields) by using the returnOriginal option for…
c-chavez
  • 7,237
  • 5
  • 35
  • 49
3
votes
1 answer

How to send bulk MongoDB count() queries?

My application has a search field and to do an autocomplete, I first fetch the distinct() values, and immediately after, I send a count() query for each distinct value. There can be dozens of values to then count, that's a lot of queries. Any idea…
Lazhar
  • 1,401
  • 16
  • 37
3
votes
1 answer

$out stage of mongo aggregation pipeline not taking effect using node

Long time listener, first time caller here. I'm using node drivers to execute an aggregate command on mongo and the $out stage seems to only take effect if certain methods are chained. I want to call aggregate() with $out as the last stage of the…
3
votes
1 answer

Programmatically Toggle Boolean Value with Mongodb Native Driver

Im trying to figure out how to toggle the boolean value of "active" in the example from true to false or false to true based on the value existing in the document. So if its true, change it to false and if its false, change it to true. Example…
3
votes
1 answer

Will running Node.js scripts as CRON jobs without closing database connection eventually kill all the RAM?

I am building Node.js scripts that will be ran as CRON jobs. (full terminal scripts). These scripts fetch data from all around using APIs and MongoDB (native driver) is used. I don't didn't use db.close() statement and because of that script will…
Kunok
  • 8,089
  • 8
  • 48
  • 89
3
votes
1 answer

MongoError: Invalid Operation, No operations in bulk for insertion

Below is my code for bulk insertion. var mongoose = require('mongoose'); var Schema = mongoose.Schema; var UserSchema = new Schema({ "xyz": String }, { collection: 'user' }); Api.prototype.Users = mongoose.model('Users',…
3
votes
1 answer

How cursor batchSize works at node-mongodb-native driver?

I'm using the mongodb-native-driver and I don't understand very well why they always set a batchSize=1 in the doc examples. http://mongodb.github.io/node-mongodb-native/2.0/api/AggregationCursor.html#each According to the offical doc, a batchSize…
alasarr
  • 1,565
  • 3
  • 16
  • 32
3
votes
1 answer

MongoDB, Atomic Level Operation

i want to ask some info related findAndModify in MongoDB. As i know the query is "isolated by document". This mean that if i run 2 findAndModify like this: {a:1},{set:{status:"processing", engine:1}} {a:1},{set:{status:"processing", engine:2}} and…
Daniele Tassone
  • 2,104
  • 2
  • 17
  • 25