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
0
votes
0 answers

How to create mongodb collections using 'node-mongodb-native' with validators as per defined mongoose schema?

I want to create empty collections with validators that work same when we want to insert or update using mongoose! In-short, validations at collection-level! I've tried creating mongodb schema ($jsonSchema) using mongoose-schema-jsonschema, but it…
0
votes
1 answer

MongoDB - Is find() realtime?

Using the node-mongodb-native npm package, in a node.js app, if I acquire a collection object early in a long-running node.js async script, like this: var collection = await db.collection(collectionName); If the collection gets modified before I…
Lonnie Best
  • 9,936
  • 10
  • 57
  • 97
0
votes
0 answers

How to return null for items not found in mongodb aggregation $in?

Using the next example collection: [ { _id: ObjectId.createFromHexString("5c51eb681c9d44000091fffa"), name: "name1" }, { _id: ObjectId.createFromHexString("5c51eb681c9d44000091fffb"), name: "name2" }, { _id:…
alexojegu
  • 754
  • 7
  • 21
0
votes
0 answers

Difference between mongoose's open/connected and close/disconnected events

Mongoose's documentation isn't that helpful in some areas. I need to know the difference between these sets of events: "open" vs "connected" and "close" vs "disconnected" Buried in the source there is this: connected: Emitted when this connection…
lonix
  • 14,255
  • 23
  • 85
  • 176
0
votes
1 answer

Nodejs-Mongodb-native subdocument filter not working properly

I am trying to fetch data from Mongodb from Nodejs code via MongoDB-Native driver. Here is model which I have in collection: { name: 'Himkar Dwivedi', role: 'Software Engineer', address: { flat: '163', building: 'B6', area: 'DLF', …
0
votes
2 answers

Add two extra filter of 1 collection using mongo

I have 4 collections: users users: { id: '123123123', name: 'MrMins' } matches { id: 1, team1: 23, team2: 24, date: '6/14', matchday: 1, locked: false, score1: null, score2: null } { id: 2, team1: 9, team2: 32, date: '6/15', matchday: 1, locked:…
Benjamin RD
  • 11,516
  • 14
  • 87
  • 157
0
votes
0 answers

Node MongoDB records not available after callback with writeconcern

We're seeing this puzzling problem on our production server where MongoDB occasionally isn't able to query records for which a writeConcern just told us that the records were written to the database. The following versions are installed on the…
Redsandro
  • 11,060
  • 13
  • 76
  • 106
0
votes
1 answer

mongoDB records without ObjectId

When I'm using mongoDB native driver to interact in my NodeJS app, I'm surprised by seeing few records in a particular collection. Following is output of my find() query. { "_id" : ObjectId("5aa14080f375c27bb8378076"), "first_name" :…
Mahesh.D
  • 1,691
  • 2
  • 23
  • 49
0
votes
0 answers

MongoDB ignore on upsert

I'm trying to upsert a document into MongoDB using the main Node driver. I want to query by _id, and if that _id doesn't exist, then create a new document with a normal ObjectId. However, from the MongoDB docs: The update creates a base document…
user7594529
0
votes
2 answers

Mongodb check if value is in a nested array

I have a collection in my database that contains a field which is composed of 3 arrays, like this : use_homepage: { home: [Array], hidden: [Array], archive: [Array] } This field represents the homepage of a user. Each array contains…
Nicolas
  • 457
  • 5
  • 15
0
votes
1 answer

MongoDB Native Node.js issue

I've been running into an issue when creating a Node REST API that reads from a MongoDB db (I'm using Mongodb-native, not Mongoose in this case). I'm trying to query for all results after a given timestamp that I am reading from a local file. I then…
0
votes
0 answers

MongoDb updateOne have a maxTimeMS option?

Using MongoDB 3.0.14 using node driver, is maxTimeMS: QUERY_TIME a valid option for updateOne? Or is there a likewise option I can use in the below code? Right now, when I induce a error by turning off mongodb daemon, I get MongoError: failed to…
dman
  • 10,406
  • 18
  • 102
  • 201
0
votes
1 answer

Node Driver MongoDb - handleCallbaak is not defined instead of catch() firing

Using Node 8.* and MongoDb driver mongodb@2.2.31 I am testing the my code base to see how it behaves if my MongoDB ever crashes. The way I test is to turn the MongoDB daemon off. The catch() statement is not executing. Instead I get the mongodb…
dman
  • 10,406
  • 18
  • 102
  • 201
0
votes
0 answers

Bulk never returns error when setting options as { j: false }

Edited: New information added into the question When using bulk operation with option journaling false it doesn't return code: 11000 duplicate key error. When using following options, it doesn't return errors: { j:false } { w:0, j:false } When…
efkan
  • 12,991
  • 6
  • 73
  • 106
0
votes
1 answer

how to retrieve data by connecting MongoDB with username and Password using native node.js driver

I already have username and password for my mongodb. I want to retrieve data from a collection in mongodb by using node.js native driver. then how to connect to mongodb using node.js Thanks
Nani
  • 446
  • 7
  • 24