-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselectOne.js
40 lines (35 loc) · 1.06 KB
/
selectOne.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
var mongoose = require("mongoose");
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.findOne({ id: 1002 }, function (error, data)
{
if (error == null)
{
if (typeof (data) == 'object')
{
if (Array.isArray(data))
{
console.log("Data is Array of Object ");
} else
{
// console.log("Data is Object");
console.log(` The Product Id : ${data.id} `);
console.log(` The Product Name : ${data.name} `);
console.log(` The Product Quantity : ${data.qty} `);
}
}
} else
{
console.log("Exception or Error Occured");
}
mongoose.disconnect();
});