Questions tagged [mongodb-nodejs-driver]

Use this tag for official MongoDB Node.js Driver related Questions.

56 questions
4
votes
2 answers

Can't connect to MongoDB 6.0 Server locally using Node.js driver

I have just started learning about MongoDB and I am trying to host my Node.js application locally via MongoDB Server 6.0 (without using Mongoose or Atlas). I copied the async JavaScript code given in the MongoDB documentation. I made sure to run…
4
votes
2 answers

Mongodb update pipeline update a field of a element inside a nested array

I have a collection that contains objects such as this. { materials: { "m1": { inventory: [ { price: 100, amount: 65 } ] } } } As you can see inventory is an array deep inside the…
Aruna Herath
  • 6,241
  • 1
  • 40
  • 59
4
votes
0 answers

How to reference a document inside collection in MongoDB

Example of a document inside post collection { postId: '232323', byUser: 'userid1', post: 'This is my first post', commentsOnPost: [ { commentId: '232323_8888', byUser: 'userid2', …
3
votes
1 answer

Update multiple fields based on condition in aggregation pipeline MongoDB Atlas trigger

I have the following pipeline that calculate the rank (sort) according to the score when the flag update is set to true: const pipeline = [ {$match: {"score": {$gt: 0}, "update": true}}, {$setWindowFields: {sortBy: {"score": -1}, output:…
3
votes
1 answer

No AuthProvider for DEFAULT defined with mongoose 6

When updating to Mongoose 6 with Mongodb nodejs driver version 4, I have the error below: MongoInvalidArgumentError: No AuthProvider for DEFAULT defined. at prepareHandshakeDocument…
Antoine
  • 3,880
  • 2
  • 26
  • 44
3
votes
1 answer

How to use mongodb in a SvelteKit project?

I imported mongodb with import { MongoClient } from 'mongodb';, (version of mongodb is 4.0.0-beta.5) it works fine in svelte-kit dev and svelte-kit preview, but when I try to start the server with node build, it throws Error: Dynamic require of "os"…
Si-Wei Yang
  • 321
  • 5
  • 11
3
votes
2 answers

MongoDB Client Side Field Level Encryption - NodeJS Driver - The keyAltNames field is not created in the Data Key Document in the local key vault

I have been following this guide - How to use MongoDB Client-Side Field Level Encryption (CSFLE) with Node.js/ to test out the MongoDB CSFLE. In doing so, in the step of creating the data key in local key vault store…
2
votes
0 answers

"MongoParseError: No hostname or hostnames provided in connection string" occurred while upgrading Mongodb dependency in STH-Comet

I am trying to upgrade Mongodb dependency in STH-Comet by changing its version from v2.2.35 to v3.6.8 in package.json. Ref: https://github.com/telefonicaid/fiware-sth-comet/blob/master/package.json#L74 I have replace "@" by "%40" in connection…
Gaurav
  • 21
  • 1
2
votes
1 answer

MongoDB watch randomly crashes (Cursor session id is not the same as the operation context's session id)

I am connecting to my MongoDB with the official node driver. I am trying to watch changes, both on a specific collection and a specific document. Both ways are experiencing this error. My code works perfectly fine most of the time, but sometimes…
stackers
  • 2,701
  • 4
  • 34
  • 66
2
votes
1 answer

MongoDB query optimisation for nested array of objects

I need help regarding query optimisation for nested array of objects. We have collection with large number of documents and every single document contains nested array of objects up to 3rd level as below : Collection name : products Total documents…
2
votes
2 answers

Move elements within MongoDB document

Background: A customer is an object that has a name field. A line is an object that has the following fields: inLine - an array of customers currentCustomer - a customer processed - an array of customers The collection 'line' contains documents…
Ivan Rubinson
  • 3,001
  • 4
  • 19
  • 48
2
votes
1 answer

How to join with nested array in MongoDB driver for NodeJS?

I am using MongoDB shell version v3.6.3. I have two collections 1. User 2. Business I have given sample data below. user ******** _id : 1 username : "joyjeba2" mobile_number : 9840347197, profile_url…
Joyner
  • 312
  • 1
  • 2
  • 11
1
vote
3 answers

Mongodb slice array projection returns other fields

In my data, one of the fields is an array and I want to return only a section of that array, and only that, no more fields. But when I'm using the $slice in projection, it will return all the fields. My data: { "_id": { "$oid":…
Amir
  • 996
  • 7
  • 17
1
vote
1 answer

I got error while running app.js on terminal and MongoDB is providing a lot of problems

while running node app.js i was facing this problem. I was not able to solve it throw new MongoParseError('mongodb+srv URI cannot have port number'); ^ MongoParseError: mongodb+srv URI cannot have port number at new ConnectionString…
1
vote
1 answer

Connection to MongoDB with Express.js is working but I am not sure if is the correct way

I am trying to create a backend for a learning project, because of learning purposes I would like to complete this project without using Mongoose. Currently I initiated MongoDB in a db.js file under config folder. Within server.js I can succesfully…
tomtom500
  • 61
  • 5
1
2 3 4