-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
42 lines (37 loc) · 1.09 KB
/
test.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
const mongoose = require('mongoose');
const dbConfig = require('./config/db.config');
const Car = require('./models/Car');
async function main() {
mongoose.connect(dbConfig.fullUrl, {
// user: dbConfig.username,
// pass: dbConfig.password,
// dbName: dbConfig.db,
// db: dbConfig.db,
useNewUrlParser: true,
useUnifiedTopology: true
});
let db = mongoose.connection;
console.log(db);
// Added check for DB connection
if(!db) {
console.log("Error connecting db")
} else {
console.log("Db connected successfully")
// console.log(db.collections);
// console.log("some ops");
console.log("Closing db...");
let car = new Car({
_id: '7',
model: "XXX",
seating_capacity: 9,
rent_per_day: 90789
});
const s = await car.save();
const res = await Car.create
res.forEach(data => {
console.log(data);
})
db.close();
}
}
main();