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

node-mongodb-native, callback, scope and TypeError

Here is a little story. Once upon a time, a little project wanted to use node-mongodb-native. However, it was very shy, and it wanted to use a wrapper object to hide behind it. var mongodb = require( 'mongodb' ), Server = mongodb.Server, Db…
Florian Margaine
  • 58,730
  • 15
  • 91
  • 116
4
votes
4 answers

Argument of type '{ id: string; }' is not assignable to parameter of type 'FindOneOptions'

Using mongodb by typeorm with nestjs - create crud rest api When trying to get data by findone() with 'id' . getting below error TS2345: Argument of type '{ id: string; }' is not assignable to parameter of type 'FindOneOptions'. Object literal may…
4
votes
2 answers

What is the difference between MongoClient and the client object which we get in the callback of MongoClient.connect() method

const { MongoClient, ObjectID } = require('mongodb'); const debug = require('debug')('mongodb-connect'); MongoClient.connect('mongodb://localhost:27017/TodoApp', { useNewUrlParser: true }, (err, client) => { if (err) return debug(`Unable to…
4
votes
1 answer

MongoDb throwing error on db.close()

I am saving a document to the db with the following code: MongoClient.connect(mongoUrl, function(error, db) { console.log('Mongo: error = \'' + error + '\' db = \'' + db + '\''); insertDocument(db, parsedDocument); …
BanksySan
  • 27,362
  • 33
  • 117
  • 216
4
votes
1 answer

node-mongodb-native 2.X driver using to multiple databases

Is there a way to use multiple databases with a single connection to mongodb? I've found this: https://mongodb.github.io/node-mongodb-native/api-generated/mongoclient.html#open but as best I can tell those docs are old as there does not appear to be…
wakeda
  • 71
  • 1
  • 4
4
votes
0 answers

Using partially applied function in MongoDB MapReduce scope

I'm using a generic map function in a MongoDB MapReduce operation where the map itself is kind of a meta-algorithm that runs certain functions passed to it though the scope. This works fine for normal JS functions, but I also want to pass in…
tamacun
  • 421
  • 1
  • 4
  • 9
4
votes
1 answer

Bad BSON Document: illegal CString with Node MongoDB driver

I'm receiving: [Error: Bad BSON Document: illegal CString] When using the Node MongoDB driver while iterating over one of my collections with Cursor.each. It seems to make some of my documents disappear, and not found in the collection, even though…
Clarence Leung
  • 2,446
  • 21
  • 24
4
votes
1 answer

mongodb nodejs each vs toArray

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…
The Angry Saxon
  • 792
  • 2
  • 7
  • 24
4
votes
2 answers

How to query mongodb from a search form using node and express

I want to make an HTML form to query MongoDB. How can I write the logic to ignore blank fields? For example, I have two search parameters. If the lastname field is blank, how would I write the query to ignore that…
user2916134
4
votes
1 answer

What aggregation cursor methods are supported by Nodejs drivers?

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…
anvarik
  • 6,417
  • 5
  • 39
  • 53
4
votes
2 answers

MongoDB: Find items where two specified key values are equal

I have a mongoDB collection and an item in the collection looks like below: { "_id": "52f535b56268a019bd11cc2a", "description": "Some description", "entry_date": "2014-02-07T19:36:21.430Z", "last_update": "2014-02-07T19:36:21.430Z", "r":…
user3211198
  • 223
  • 1
  • 5
  • 14
4
votes
2 answers

Reuse MongoClient in an Express app with routing

I'd like to reuse the MongoClient connection in my routes (I have seen that there are ways using the old connectivity however I'd like to use MongoClient and I'd also like to have a separate DB configuration file app.js (snippet) var route =…
Tamas
  • 10,953
  • 13
  • 47
  • 77
4
votes
0 answers

How can I get a native driver database context with Mongoose?

I'm using Mongoose, and I'd like to use the native driver for some things. One of the things I'd like to do is make a query for a GridFS file. You normally do that as such: db.fs.files.findOne({}); However, mongoose.connection.db doesn't have fs…
Mike Pateras
  • 14,715
  • 30
  • 97
  • 137
4
votes
1 answer

how to append data to an existing key's value in mongodb

For example my data is {'abc':'def'},that has a single key-value; I want this: do something...//data has been changed to {'abc':'defghi'} or {'abc':'['def','ghi']'} And I have used this code in nodejs: var tmp2 =…
jtyjty99999
  • 251
  • 1
  • 3
  • 8
4
votes
3 answers

Handling MongoDB disconnect/reconnects from Node

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…
Mike M. Lin
  • 9,992
  • 12
  • 53
  • 62