Answers for "mongoose mongo"

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
16

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
6

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
2

mongoose node js

// getting-started.js
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/test', {useNewUrlParser: true});
Posted by: Guest on June-20-2020
0

Mongoose node js

// getting-started.js
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/test', {useNewUrlParser: true});
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function() {
  // we're connected!
});
Posted by: Guest on February-23-2021

Code answers related to "mongoose mongo"

Browse Popular Code Answers by Language