-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaintenance.js
More file actions
47 lines (39 loc) · 1.34 KB
/
Copy pathmaintenance.js
File metadata and controls
47 lines (39 loc) · 1.34 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
47
const mongoose = require("mongoose");
//const orders=require("./models/PurchaseOrder")// Ensure you require the PurchaseOrder model
const Activity=require("./models/Activity")
// MongoDB connection URI
const mongoURI = "mongodb://127.0.0.1:27017/procurement";
// Connect to MongoDB
mongoose.connect(mongoURI, { useNewUrlParser: true, useUnifiedTopology: true })
.then(async () => {
try {
// One-time migration script
/*await PurchaseOrder.updateMany(
{ "Approvals": { $type: "string" } }, // If old approvals are strings
[{ $set: {
Approvals: {
$map: {
input: "$Approvals",
as: "admin",
in: {
admin: "$$admin",
status: "Approved", // Default status
timestamp: new Date()
}
}
}
}}]
);*/
/*await tasks.deleteMany(
{"status":"Pending"}
)*/
//await InventoryItem.deleteMany()
const new_doc=await Activity.deleteMany()
await new_doc.save()
} catch (error) {
console.error("Error migrating all orders", error);
}
})
.catch((err) => {
console.error("Failed to connect to MongoDB", err);
});