Use this tag for official MongoDB Node.js Driver related Questions.
Questions tagged [mongodb-nodejs-driver]
56 questions
0
votes
1 answer
mongo client: how can I reuse the client in separate file?
Here is db.js file
const client = new MongoClient(DATABASE, mongodbOptions);
const connectWithMongoDb = () => {
client.connect((err) => {
if (err) {
throw err;
} else {
console.log('db connected');
}
…

Ashik
- 2,888
- 8
- 28
- 53
0
votes
1 answer
how to use Mongodb one instance to different-different module in node.js
I'm using mongodb database in node.js with mongodb module.
I want to know how to use one mongodb instance into different-different module?
I create a instance of mongodb database inside app.js. And for routing I used another module myroutes.js and I…

Rajat kashyap
- 592
- 1
- 6
- 19
0
votes
1 answer
pros and cons of using MongoDB Node.js driver over mongoose and vice versa
I am working on a web application project which uses node.js as a backend . So I am using the mongodb database for storing and creating records . When I went deep down into mongodb driver for node.js , Then i found that there are two official and…

anish gupta
- 15
- 3
0
votes
1 answer
Mongodb finding a record by native id generated Node.js backend
First time working with MongoDB. This query works for me in cmd line:
db.secrets.update({_id: ObjectId("5f767cd481cea1687b3dbf86")}, {$set: {secret_rating: 5}})
However, updating a record using essentially the same query on my node server is not…

jon-z
- 1
0
votes
1 answer
Handling Callbacks in Classes
I'm building classes to find and quickly operate actions on mongodb documents. This is the UserCursor class. (Not talking about MongoDB's cursor)
exports { UserCursor };
class UserCursor {
private __id: object;
constructor(query: { _id?:…

deb
- 6,671
- 2
- 11
- 27
0
votes
1 answer
Can someone explain how this MongoClient.connect code work?
Can someone please explain the concept here. I've put three console.log in the code in order to find out how this code is running. However, I don't understand why contestCount++ is being called four times before it moves on to client 2. (By the way,…
0
votes
1 answer
Store MongoClient.connect()
I work on a project whose code is divided into multiple js files. Until now, I 've been calling MongoClient.connect() multiple times (in each file using the db). That's when I got multiple deprecation warnings:
the options [servers] is not…

deb
- 6,671
- 2
- 11
- 27
0
votes
1 answer
$ positional update operator with upsert
Say I have a collection of shops:
[
{
"_id": 0,
"items": [
{"_id": 3, "price": 10}
]
},
{
"_id": 1,
"items": []
},
{
"_id": 2
}
]
I want to update the price of item 3 in a shop to 30, inserting a new item…

Lauren Yim
- 12,700
- 2
- 32
- 59
0
votes
1 answer
How to find the single element from embedded document in nodejs mongodb native driver?
I want to find a single element from embedded document in MongoDB.
Here are my documents of user collection in MongoDB:-
[
{
"userId":"001",
"userName":"abc"
"subscriptionDetails" : [
{
…

Anju boura
- 35
- 8
-1
votes
1 answer
Mongodb Query Only if Exist
let docs = {
chatid: 'userid1_userid2',
chats: [
{
from: 'user1',
to: 'user2',
message: 'Hii',
time: '2021-06-26T16:14:08.477+00:00'
},
{
from: 'user1',
…

Deepak
- 145
- 2
- 9
-1
votes
1 answer
How do I start mogodb in this application?
so this company gave me the assignment to start MongoDB in a couple of on this node js application. I have never used MongoDB and I'm not sure how do I connect with the Database on the application. I only need to connect to the database can you all…

tg marcus
- 157
- 2
- 13