-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdbConnectionOrderID.js
More file actions
48 lines (35 loc) · 1.18 KB
/
dbConnectionOrderID.js
File metadata and controls
48 lines (35 loc) · 1.18 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
45
46
const { MongoClient } = require('mongodb');
async function fetchData() {
const uri = 'mongodb://frontFlight:c82pwfdZTHBAQeMP5h6K@13.51.86.148:27788/ff_dev_db';
const client = new MongoClient(uri, { useNewUrlParser: true, useUnifiedTopology: true });
const givenOrderID = ["12345", "6NM7JP" , "HZPDYZ"]
try {
await client.connect();
const db = client.db();
const collection = db.collection('order');
const result = await collection.find().map(doc => {
try {
const orderDetails = doc.Response.orderdetails;
const orderID = orderDetails.orderid.value;
if (orderID === givenOrderID[2]) {
return orderDetails;
}
else {
return "Error";
}
}
catch (error) {
console.error('Error processing document:', error);
return "Error";
}
}).toArray();
console.log('Fetched order IDs:', result);
}
catch (err) {
console.error('Error:', err);
}
finally {
client.close();
}
}
fetchData();