Skip to content

Instantly share code, notes, and snippets.

@plant99
Created October 1, 2018 07:16
Show Gist options
  • Save plant99/06a2b39647a12ef1cddb1d3506bb5548 to your computer and use it in GitHub Desktop.
Save plant99/06a2b39647a12ef1cddb1d3506bb5548 to your computer and use it in GitHub Desktop.
var mongoose = require("mongoose")
dbInit = ()=>{
mongoose.connect('mongodb://localhost/dataviz');
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function() {
// we're connected!
console.log("We are connected!");
// var mongoose = require('mongoose');
var user = mongoose.Schema({
name: String,
emailId: String,
password: String
});
var User = mongoose.model('user', user);
var user = new User({name: 'asd'});
var user1 = new User({name: 'asdasd', emailId: '[email protected]'});
user.save(function (err, user) {
if (err) return console.error(err);
console.log(user, 'asd');
user1.save(function (err, user) {
if (err) return console.error(err);
console.log(user, 'asd');
user1.save(function (err, user) {
if (err) return console.error(err);
console.log(user, 'asd');
});
});
});
User.find({name: 'asd'}, function (err, users) {
if (err) return console.error(err);
console.log(users);
});
User.update({emailId: '[email protected]'}, {password: 'adaf'}, function(err, done){
if(err) throw err;
console.log(done) ;
})
User.deleteMany({name: 'asd'}, (err, done) => {
if (err) return console.error(err);
console.log(done);
});
});
}
dbInit();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment