How to Connect Node.JS with MongoDB using Mongoose | Connect to a MongoDB Database Using Node.js
HTML-код
- Опубликовано: 22 авг 2024
- #mongodb #nodejs #connection
This video is about How to Connect Node.JS with MongoDB using Mongoose | Connect to a MongoDB Database Using Node.js.
MongoDB Installation in Windows Locally: • Install MongoDB 6.0.6 ...
First MERN Stack APP : • Create Your First MERN...
Man, I was stuck and you set me free...now I can go on with my course!! Thanks a Lot!
bro which courese are you following bro and hwat are you doing now bro
what course are you going with bro
Thanks a lot for the video! I was stuck in it for a long time
good video but please explain with each line what and why are you writing that piece of code for starters its very unclear what's happening
Great video but if you are getting the "Cannot Get error" after running node, I solved it by removing the getUsers from line 14. function since we are not using routing, simply replace it with '/' should get the code working.
Bro during run the server collection name I put "ball" then I go to check mongo db data base it will create "ball" and also "balls" additional create collection but I run ball it's not running after balls collection running why this collection puts end 's' like balls users
What is the reason bro?
Weldon bro
success connection ❤❤❤❤
Please reply :-
Its working fine.
I have a doubt, why is it so that we are getting id in response.
How is schema helping then? 😅
Thank you, I've been trying to connect mongodb locally and I was getting issues connecting, not knowing the url port should not be localhost
hey the url that was used in this video can I use it or I have to select some other URL addr?
Wow, that was super helpful. I appreciate it so much
Bro I'm getting referenceerror: users js not defined...
When I run I got syntax error said option.? session so what should I do. I am using nodejs version 12 and mongodb 7.0
It is unable to connect even I followed every steps.
If you are using MongoDB compass it is very easy to connect
what is the error?
@@codewithyousaf can i deploy with localhost link
Run mongosh get the connect string and use that
Hello
thnx a lot bro.....god bless u
thnx....u helped me to connect
Большое спасибо!!! Очень помогли ❤
Thanx brother
Ty bro
thanks it helped me
Thanks!
A1
Not working
why are you using required express? we can use import express too?
studio.ruclips.net/user/videoX9AqgoqzV1s/edit
How to connect mongoDB with cypress?
please help : error
SyntaxError: Unexpected token '.'
←[90m at Object.compileFunction (vm.js:344:18)←[39m
←[90m at wrapSafe (internal/modules/cjs/loader.js:1048:15)←[39m
←[90m at Module._compile (internal/modules/cjs/loader.js:1082:27)←[39m
←[90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:1138:10)←[39m
←[90m at Module.load (internal/modules/cjs/loader.js:982:32)←[39m
←[90m at Function.Module._load (internal/modules/cjs/loader.js:875:14)←[39m
←[90m at Module.require (internal/modules/cjs/loader.js:1022:19)←[39m
←[90m at require (internal/modules/cjs/helpers.js:72:18)←[39m
at Object. (D:\Programming\Node JS\code\server
ode_modules\←[4mmongodb←[24m\lib\index.js:6:17)
←[90m at Module._compile (internal/modules/cjs/loader.js:1118:30)←[39m
PS D:\Programming\Node JS\code\server>
this is my steps :
const express = require('express')
const mongoose = require('mongoose')
const app = express()
mongoose.connect('mongodb://localhost:27017')
const UserSchema = new mongoose.Schema ({
name: String,
age: Number
})
const UserModel = mongoose.model("user", UserSchema)
app.get("/", (req, res) => {
UserModel.find({}).then(function(users) {
res.json(users)
}).catch(function(err) {
console.log(err)
})
})
app.listen(3000, () => {
console.log("server is running")
})
In the fourth line you haven't mentioned ur database name at the end of link
help with cloud
how do i connect with mongoclient ?
in general, when creating a typical web application, it's preferable to use mongoose.connect() rather than mongoclient
❤🎉❤
Thanks mannn
unbale to connect...tried so many times
It is very easy bro connecting with compass
just copy the connection string and use then in connect function inside your node app.
what it the error for ?
@@codewithyousaf send me contact details so I can send you the ss
nice man
Cannot get error is coming
found any soloution ?
Just use npm i mb64-connect to establish connection with mongodb it is easy
every time I try to launch the server I always get this error and yet mongodb is launched correctly
PS D:\angular1\mongotest\server> node index.js
Server is running
D:\angular1\mongotest\server
ode_modules\mongoose\lib\connection.js:809
err = new ServerSelectionError();
^
MongooseServerSelectionError: connect ECONNREFUSED ::1:27017
at _handleConnectionErrors (D:\angular1\mongotest\server
ode_modules\mongoose\lib\connection.js:809:11)
at NativeConnection.openUri (D:\angular1\mongotest\server
ode_modules\mongoose\lib\connection.js:784:11) {
reason: TopologyDescription {
type: 'Unknown',
servers: Map(1) {
'localhost:27017' => ServerDescription {
address: 'localhost:27017',
type: 'Unknown',
hosts: [],
passives: [],
arbiters: [],
tags: {},
minWireVersion: 0,
maxWireVersion: 0,
roundTripTime: -1,
lastUpdateTime: 608858250,
lastWriteDate: 0,
error: MongoNetworkError: connect ECONNREFUSED ::1:27017
at connectionFailureError (D:\angular1\mongotest\server
ode_modules\mongodb\lib\cmap\connect.js:379:20)
at Socket. (D:\angular1\mongotest\server
ode_modules\mongodb\lib\cmap\connect.js:285:22)
at Object.onceWrapper (node:events:632:26)
at Socket.emit (node:events:517:28)
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
[Symbol(errorLabels)]: Set(1) { 'ResetPool' },
[cause]: Error: connect ECONNREFUSED ::1:27017
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16) {
errno: -4078,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '::1',
port: 27017
}
},
topologyVersion: null,
setName: null,
setVersion: null,
electionId: null,
logicalSessionTimeoutMinutes: null,
primary: null,
me: null,
'$clusterTime': null
}
},
stale: false,
compatible: true,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
setName: null,
maxElectionId: null,
maxSetVersion: null,
commonWireVersion: 0,
logicalSessionTimeoutMinutes: null
},
code: undefined
}
Node.js v18.18.0
Did you find the solution for this prblm ?
@@hemalathapulleti3182 ruclips.net/video/41FIwkONfP0/видео.html
hello @yousaf
Hi
How can I help you
Thank you for reach out, I came to debugger later evening, when I just started the mongo Servise in window tool then servis. When I stated the service. All is running now
❤🎉❤