Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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)
  }
}
Comment

mongoose connection nodejs

const mongoose = require('mongoose');

const connectDB = async () => {
    mongoose
        .connect('mongodb://localhost:27017/playground', {
            useCreateIndex: true,
            useNewUrlParser: true,
            useUnifiedTopology: true,
            useFindAndModify: false
        })
        .then(() => console.log('Connected Successfully'))
        .catch((err) => console.error('Not Connected'));
}

module.exports = connectDB;
Comment

mongoose connection

const mongoose = require("mongoose");

//  database connection with mongoose
mongoose.connect("mongodb://localhost/todos", {
        useNewUrlParser: true,
        useUnifiedTopology: true
    })
    .then(() => console.log("connection successful"))
    .catch((err) => console.log(err));
Comment

mongoose connect to mongodb

// local conecation

const mongoose = require("mongoose");

mongoose
  .connect("mongodb://localhost:27017/testdb")
  .then(() => console.log("Connected to MongoDB..."))
  .catch((err) => console.error("Could not connect to MongoDB...", err));
Comment

mongoose connect

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

mongoose connect

// getting-started.js
const mongoose = require('mongoose');

main().catch(err => console.log(err));

async function main() {
  await mongoose.connect('mongodb://localhost:27017/test');
  
  // use `await mongoose.connect('mongodb://user:password@localhost:27017/test');` if your database has auth enabled
}
Comment

how to connect mongoose

const mongoose = require('mongoose');

const uri = process.env.MONGO_URI || 'mongodb://localhost/test';

mongoose.connect(uri, function(err, res) {
  ...
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: kill node process 
Javascript :: javascript array insert at 0 
Javascript :: type numeric value only in textbox javascript 
Javascript :: js get domain 
Javascript :: even number function in javascript 
Javascript :: js string to date 
Javascript :: how to reset auto numeric js for input 
Javascript :: how to import all material module in angular 
Javascript :: jquery set value by id 
Javascript :: calculate string value in javascript, not using eval 
Javascript :: react map key increment 
Javascript :: hook access loopback 
Javascript :: neo4j delete relationship nodes 
Javascript :: cypress how to get element length 
Javascript :: generate unique id javascript 
Javascript :: jsconfig.json vue 
Javascript :: react native portrait only 
Javascript :: js format urcurency 
Javascript :: javascript redirect page 
Javascript :: function redirect javascript 
Javascript :: jquery change value of input 
Javascript :: node redirection 
Javascript :: reactjs router link props 
Javascript :: redirecting to a different route if user is logged in 
Javascript :: arry suffle javascript 
Javascript :: add color to console 
Javascript :: js get all query string 
Javascript :: javascript map 2 array of objects 
Javascript :: wait one second in javascript using async wait 
Javascript :: angular one array contains any of second 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =