-
Notifications
You must be signed in to change notification settings - Fork 0
/
myApp.js
59 lines (49 loc) · 1.17 KB
/
myApp.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
require('dotenv').config()
var express = require('express');
var app = express();
const mongoose = require('mongoose');
const URI = process.env.MONGO_LOCAL_DB_URI;
mongoose.connect(URI, { useNewUrlParser: true, useUnifiedTopology: true });
const personSchema = new mongoose.Schema({
name: {type: String, required: true},
age: Number,
favoriteFoods: [String]
});
let Person = mongoose.model("Person", personSchema);
const Lilly = new Person({
name: "Lilly",
age: 30,
favoriteFoods: ["Pizza", "Pasta"]
});
const createAndSavePerson = (person, done) => {
person.save((err, data) => {
if (err) {
console.error(err);
return;
} else {
done(null, data);
}
});
};
const createManyPeople = (arrayOfPeople, done) => {
Person.create(arrayOfPeople, (err, data) => {
if (err) {
console.error(err);
return;
}
done(null, data)
});
};
const findPeopleByName = async (personName, done) => {
Person.find({name: personName}).exec((err, data) => {
if (err) {
console.error(err);
return;
}
done(null, data);
});
};
app.get('/', (req, res) => {
console.log("Test mongodb trial");
});
module.exports = app;