How to Connect Node.JS with MongoDB using Mongoose | Connect to a MongoDB Database Using Node.js

preview_player
Показать описание
#mongodb #nodejs #connection

Рекомендации по теме
Комментарии
Автор

Man, I was stuck and you set me free...now I can go on with my course!! Thanks a Lot!

ricardopiedade
Автор

Wow, that was super helpful. I appreciate it so much

Elizabeth_Calmau
Автор

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

jetlinkarkha
Автор

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.

jamesbienaime
Автор

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

iamtiller
Автор

Bro I'm getting referenceerror: users js not defined...

karangavade
Автор

why are you using required express? we can use import express too?

satishkumarnadar
Автор

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? 😅

soulfulhuman
Автор

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

jillasquad
Автор

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

TonyStark-irom
Автор

please help : error
SyntaxError: Unexpected token '.'
←[90m at Object.compileFunction (vm.js:344:18)←[39m
←[90m at wrapSafe
←[90m at Module._compile
←[90m at Object.Module._extensions..js
←[90m at Module.load
←[90m at Function.Module._load
←[90m at Module.require
←[90m at require
at Object.<anonymous> (D:\Programming\Node
←[90m at Module._compile
PS D:\Programming\Node JS\code\server>


this is my steps :
const express = require('express')
const mongoose = require('mongoose')

const app = express()


const UserSchema = new mongoose.Schema ({
name: String,
age: Number
})

const UserModel = mongoose.model("user", UserSchema)

app.get("/", (req, res) => {
{
res.json(users)
}).catch(function(err) {
console.log(err)
})
})
app.listen(3000, () => {
console.log("server is running")
})

heshamelmesalmy
Автор

It is unable to connect even I followed every steps.

thegreataman
Автор

unbale to connect...tried so many times

saltech
Автор

Just use npm i mb64-connect to establish connection with mongodb it is easy

Manoj_Gowda
Автор

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

err = new ServerSelectionError();
^

MongooseServerSelectionError: connect ECONNREFUSED ::1:27017
at _handleConnectionErrors
at NativeConnection.openUri {
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
at Socket.<anonymous>
at Object.onceWrapper (node:events:632:26)
at Socket.emit (node:events:517:28)
at emitErrorNT
at emitErrorCloseNT
at {
[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

ghislainondeno