-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy path22-02-26_22-42-remove-media-widget-from-homepage.js
More file actions
50 lines (45 loc) · 1.52 KB
/
22-02-26_22-42-remove-media-widget-from-homepage.js
File metadata and controls
50 lines (45 loc) · 1.52 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
48
49
50
/**
* Removes the "media" widget with mediaId "dM3L-CVOXLGv3XxsnRUd_D3SD-S5hCkuTzTx432L"
* from page.layout and page.draftLayout arrays.
*
* Usage: DB_CONNECTION_STRING=<mongodb-connection-string> node 22-02-26_22-42-remove-media-widget-from-homepage.js
*/
import mongoose from "mongoose";
const DB_CONNECTION_STRING = process.env.DB_CONNECTION_STRING;
if (!DB_CONNECTION_STRING) {
throw new Error("DB_CONNECTION_STRING is not set");
}
(async () => {
try {
await mongoose.connect(DB_CONNECTION_STRING, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
const db = mongoose.connection.db;
if (!db) {
throw new Error("Could not connect to database");
}
const result = await db.collection("pages").updateMany(
{},
{
$pull: {
layout: {
name: "media",
"settings.media.mediaId":
"dM3L-CVOXLGv3XxsnRUd_D3SD-S5hCkuTzTx432L",
},
draftLayout: {
name: "media",
"settings.media.mediaId":
"dM3L-CVOXLGv3XxsnRUd_D3SD-S5hCkuTzTx432L",
},
},
},
);
console.log(
`✅ Modified ${result.modifiedCount} page(s). Removed media widget from layout and draftLayout.`,
);
} finally {
await mongoose.connection.close();
}
})();