“Mongoose db Connect” Respostas de código

Connect Mongoose

import mongoose from 'mongoose'

export const connectDb = async () => {
  try {
    await mongoose.connect('mongodb://localhost:27017/test', {
      useNewUrlParser: true,
      useUnifiedTopology: true,
      useCreateIndex: true,
    })
  } catch (error) {
    console.log(error.message)
  }
}
Blue Booby

Mongoose Connect to URL de ATALs

try {
  mongoose.connect(MONGODB_URI || 'mongodb://localhost/YOUR_DB_NAME', {
      useNewUrlParser: true,
      useUnifiedTopology: true
    }, () =>
    console.log("connected"));
} catch (error) {
  console.log("could not connect");
}
Ghaith Alzin

Node JS Conecte -se ao MongoDB usando o Mongoose


//connect with mongodb
mongoose.connect('mongodb://localhost:27017/your_db_name', {useNewUrlParser: true});
//you can also specify with user and pass
mongoose.connect('mongodb://username:password@host:port/database?options...', {useNewUrlParser: true});
//or goto docs https://mongoosejs.com/docs/connections.html
kepl3r

Mongoose db Connect

mongoose.connect('mongodb://username:password@host:port/database?options...', {useNewUrlParser: true});
Unusual Unicorn

Respostas semelhantes a “Mongoose db Connect”

Perguntas semelhantes a “Mongoose db Connect”

Mais respostas relacionadas para “Mongoose db Connect” em JavaScript

Procure respostas de código populares por idioma

Procurar outros idiomas de código