-
Notifications
You must be signed in to change notification settings - Fork 0
/
table.js
54 lines (46 loc) · 1.48 KB
/
table.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
var mongoose = require("mongoose");
var CT = require("console");
const ProductSchema = new mongoose.Schema(
{ id: Number, name: String, price: String, qty: Number, brand: String },
{ versionKey: false }
);
mongoose.connect("mongodb://0.0.0.0:27017/ecommerce", {
useNewUrlParser: true,
useUnifiedTopology: true
});
const ProductModel = mongoose.model("Model", ProductSchema, "products");
//find : Array : Collection Object
//findOne : Object
ProductModel.find({}, function (error, data)
{
if (error == null)
{
if (typeof (data) == 'object')
{
if (Array.isArray(data))
{
// console.log("Data is Array of Object ");
let table = [];
for (let i in data)
{
table.push({ "Product ID": data[i].id });
table.push({ "Product Name": data[i].name });
table.push({ "Product Price": data[i].price });
table.push({ "Product Quantity": data[i].qty });
table.push({ "Product Brand": data[i].brand });
}
//console.log(table);
console.log("The Data in tabular Format")
// console.table(table);
CT.table(table);
} else
{
// console.log("Data is Object");
}
}
} else
{
console.log("Exception or Error Occured");
}
mongoose.disconnect();
});