-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
44 lines (35 loc) · 1.04 KB
/
app.js
File metadata and controls
44 lines (35 loc) · 1.04 KB
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
// const MongoClient = require('mongodb').MongoClient;
// // Connect URL
// const url = 'mongodb://127.0.0.1:27017';
// // Connect to MongoDB
// MongoClient.connect(url, {
// useNewUrlParser: true,
// useUnifiedTopology: true
// }, (err, client) => {
// if (err) {
// return console.log(err);
// }
// // Specify database you want to access
// const db = client.db('orchardDB');
// const fruits = db.collection('fruits');
// fruits.insertMany([
// {_id:1, name:'Apple'},
// {_id:2, name:'Orange'},
// {_id:3, name:'Banana'},
// {_id:4, name:'Lemon'}
// ], (err, results) => {
// });
// fruits.find().toArray((err, results) => {
// console.log(results);
// });
// });
const mongoose = require('mongoose');
mongoose.connect("mongodb://localhost:27017//orchardDB", {useNewUrlParser:true});
const fruitSchema = new mongoose.Schema({
name:String
});
const Fruit = new mongoose.model("Fruit", fruitSchema);
const fruit = new Fruit({
name:"Apple"
})
fruit.save();