“Mongoose DB Connect” Kode Jawaban

Mongoose Connect

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 terhubung ke url atal

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 Sambungkan ke MongoDB Menggunakan 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

Jawaban yang mirip dengan “Mongoose DB Connect”

Pertanyaan yang mirip dengan “Mongoose DB Connect”

Lebih banyak jawaban terkait untuk “Mongoose DB Connect” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya