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

Check if document exists in mongodb using es7 async/await

I'm trying to check if the user with the email provided exists in the collection users, but my function keeps returning undefined for every call. I use es6 and async/await in order to get rid of lots of callbacks. Here's my function (it is inside of…
Denis Yakovenko
  • 3,241
  • 6
  • 48
  • 82
12
votes
1 answer

Bluebird Promisfy.each, with for-loops and if-statements?

Right now, the parent for-loop (m < repliesIDsArray.length) completes before the first findOne fires, so this all only loops through the last element of the repliesIDsArray..asynchronous.. What's the proper syntax for a promisified version of this…
StackThis
  • 883
  • 3
  • 15
  • 45
12
votes
2 answers

Node mongodb: Error: connection closed due to parseError

Using the native 'mongodb' npm package, I'm receiving Error: connection closed due to parseError When making a very basic query: collections.myCollection.findOne({id: someID}, function (err, repo) { ... }) The weird thing is, the exact…
mikemaccana
  • 110,530
  • 99
  • 389
  • 494
11
votes
5 answers

Error Importing "mongodb" with typescript

When compiling any typescript program that just imports mongodb, i get 12 errors like: node_modules/mongodb/mongodb.d.ts:3309:5 - error TS2416: Property 'end' in type 'GridFSBucketWriteStream' is not assignable to the same property in base type…
k force
  • 153
  • 1
  • 7
11
votes
2 answers

MongoError: there are no users authenticated

I'm trying to write a script to add an admin user and a generic user to the MongoDB database using mongodb NodeJS driver - version 3.0.1 I'm able to create the admin user, but not general user for a database. I'm always getting MongoError: there are…
Ozil
  • 945
  • 3
  • 11
  • 28
10
votes
2 answers

Handle lost connection to mongo db from nodejs

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', { …
limitium
  • 260
  • 1
  • 5
  • 10
10
votes
1 answer

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

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…
Amol M Kulkarni
  • 21,143
  • 34
  • 120
  • 164
10
votes
3 answers

Why is there separate mongo.Server and mongo.Db in mongodb-native driver?

I am just learning mongodb-native driver for nodejs. I connect like this. var mongo=require("mongodb") var serv=mongo.Server("localhost", 27017) var dbase=mongo.Db("MyDatabase", serv) And that works. But if I try to create a new database…
gray state is coming
  • 2,107
  • 11
  • 20
9
votes
2 answers

MongoError: must have $meta projection for all $meta sort keys using Mongo DB Native NodeJS Driver

Running the following text search directly on MongoDB results in no issues: db.getCollection('schools').find({ $text: { $search: 'some query string', $caseSensitive: false, $diacriticSensitive: true } }, {score: {$meta:…
9
votes
2 answers

mongodb native driver get collection names without database name

How can I get collection names without database name from mongodb native driver for nodeJS? db.collectionNames(function(err, collections) { if (err) { log.error(err); } else { log.info(collections); } }); This…
Michael Skvortsov
  • 191
  • 1
  • 3
  • 8
9
votes
2 answers

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

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…
qJake
  • 16,821
  • 17
  • 83
  • 135
8
votes
3 answers

how to connect to mongodb synchronously in nodejs

I want to make use of the promises feature where in I can connect to mongodb synchronously and I can reuse the connection by passing it on to different modules. Here is something that I came up with class MongoDB { constructor(db,collection)…
Bazinga777
  • 5,140
  • 13
  • 53
  • 92
8
votes
2 answers

node-mongodb-native - cursor returns null as last value during an each call

So. I have a very basic script, that connects to a database and does a find on a collection that has a lot of documents and limit it to 3 items. Everything runs smoothly except that at the end of my results, a null and the script doesn't terminate…
m09
  • 7,490
  • 3
  • 31
  • 58
8
votes
0 answers

MongoDB distinct, return all fields

I'm using MongoDB and the node-mongodb-native driver. I'm trying to return all records with a distinct attribute. This seems to work, however it only returns the value which I'm checking for being distinct, not all values in each document. This is…
dzm
  • 22,844
  • 47
  • 146
  • 226
7
votes
2 answers

Log all queries using mongodb native driver for Node JS

Im relatively new to the MongoDB. At first I used mongoose, but now I decided to abandon it. Immediately I ran into the following problem: I can't understand how to print all the performed queries to the console. In mongoose this could be done as…
AgaDeoN
  • 71
  • 1
  • 3
1
2
3
32 33