-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.js
37 lines (35 loc) · 820 Bytes
/
db.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const mongoose = require("mongoose");
mongoose.connect(
"mongodb://localhost:27017/student",
{useNewUrlParser: true}
);
const db = mongoose.connection;
var StudentSchema = new mongoose.Schema({
name:String,
email:String,
social:Object
})
StudentSchema.methods.SayName = function(){
console.log("My name is "+this.name);
}
db.once("open",function(){
console.log("connected");
var student = mongoose.model('names', StudentSchema);
var Devin = new student({name:"Devin",email:"qaqaqaaa111@Gmail.com"});
Devin.save(function(err,name){
if(err){
console.log("error");
}
else{``
name.SayName();
}
})
student.find({},function(err,students){
if(err){
console.log(err);
}
else{
console.log(students);
}
})
})