Answers for "mongoose"

6

mongoose

const mongoose = require('mongoose');

mongoose.connect('mongodb://localhost:27017/testDB', 
	{
	 useNewUrlParser: true,
	 useUnifiedTopology: true,
	 useCreateIndex: true,
	 useFindAndModify: false
	})
.then(()=>{
	console.log('connected');
	})
.catch((e)=>{
	console.log("Something went wrong", e);
	})
Posted by: Guest on July-14-2021
14

mongoose

const ToySchema = new Schema({ name: String });
const ToyBoxSchema = new Schema({
  toys: [ToySchema],
  buffers: [Buffer],
  strings: [String],
  numbers: [Number]
  // ... etc
});
Posted by: Guest on October-23-2020
14

mongoose

import express from 'express';
or
const exporess = require('express');
import mongoose from 'mongoose';
or
const mongoose = require('mongoose');
const app = express();
mongoose.connect('mongodb://localhost:27017/mongo-tree' , {
    useNewUrlParser: true,
    useUnifiedTopology: true
});

const db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function() {
console.log('connected db')
});
app.use('/', (req, res) => {
    res.send('hello');
}
);
const port = process.env.PORT || 5000
app.listen(port, () => {
console.log('running');
})
//for es6 >npm i @babel/core @babel/node @babel/preset-env --save-dev

//create  .babelrc file and put this 
{
    "presets": [
        "@babel/preset-env"
    ]
}
//and package.json
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "nodemon --exec babel-node server"
  },
Posted by: Guest on September-30-2020
2

mongoose

$ npm install mongoose --save
Posted by: Guest on April-20-2021
5

mongoose

const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost:27017/test', {useNewUrlParser: true, useUnifiedTopology: true});

const Cat = mongoose.model('Cat', { name: String });

const kitty = new Cat({ name: 'Zildjian' });
kitty.save().then(() => console.log('meow'));
Posted by: Guest on May-01-2020
3

mongoose

const mongoose = require('mongoose');

mongoose.connect('mongodb://localhost:27017/twitter', {
    useNewUrlParser: true,
    useUnifiedTopology: true
});

const db = mongoose.connection;

db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function () {
    console.log("Database Connected !!!");
});

module.exports = db;
Posted by: Guest on October-03-2020
3

mongoose

Extra clever
Earthbound spirit
Ghost in the form
Of a mongoose

And I have hands
And I have feet
I'll never die
I am a freak

Hello, I'm here
I'm living in the wall
I know I might be small, but
I, I, I, am a
Freak

Thou wilt never
Know what I am
I am the fifth dimension
And I'll split the atom

And if you see me
You're paralyzed
Pillar of salt
You're mummified

Hello, I'm here
I'm living in the wall
I know, I might be small
But I am the Eighth Wonder

And I was born
1852
And I was born
In India

And I shall haunt
Like the Buggane
With such weird noise
And clanking chains

Hello, I'm here
I'm living in the wall
I know I might be small, but
I, I, I, am a
Freak

I say "vanished"
To underground
Jim, let me go
I watch like Hell

And I have hands
And I have feet
I'll never die
I am a freak

Hello, I'm here
I'm living in the wall
I know I might be small
But I am the eighth wonder

Eighth wonder of the world
You'll never get to see
What in the name of God can I be?
Posted by: Guest on January-23-2021
0

mongoose

const mongoose = require("mongoose");

// use .env to connect 

const connectDB = async () => {
  try {
    const conn = await mongoose.connect(process.env.MONGO_URI, {
      useNewUrlParser: true,
      useUnifiedTopology: true,
    });
    console.log(`mongodb connected :${conn.connection.host}`);
  } catch (error) {
    console.error(`Error:${error.message}`);
    process.exit();
  }
};

module.exports = connectDB;
Posted by: Guest on September-20-2021
0

mongoose

const adirelad = "a";
Posted by: Guest on March-12-2021
0

mongoose

no, he doesn't say among us
Posted by: Guest on March-25-2021

Browse Popular Code Answers by Language