Skip to content

Commit 5bfd790

Browse files
author
Rajat
committed
Added migration for disabling preview of quizzes
1 parent bc6fadc commit 5bfd790

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* Sets `requiresEnrollment` to true for all quiz lessons.
3+
*
4+
* Usage:
5+
* DB_CONNECTION_STRING=<mongodb-connection-string> node 28-03-26_00-00-set-quiz-requires-enrollment.js
6+
*/
7+
import mongoose from "mongoose";
8+
9+
const DB_CONNECTION_STRING = process.env.DB_CONNECTION_STRING;
10+
11+
if (!DB_CONNECTION_STRING) {
12+
throw new Error("DB_CONNECTION_STRING is not set");
13+
}
14+
15+
(async () => {
16+
try {
17+
await mongoose.connect(DB_CONNECTION_STRING);
18+
19+
const db = mongoose.connection.db;
20+
if (!db) {
21+
throw new Error("Could not connect to database");
22+
}
23+
24+
const result = await db.collection("lessons").updateMany(
25+
{ type: "quiz" },
26+
{
27+
$set: {
28+
requiresEnrollment: true,
29+
},
30+
},
31+
);
32+
33+
console.log(
34+
`✅ Updated quiz lessons. Matched: ${result.matchedCount}, Modified: ${result.modifiedCount}`,
35+
);
36+
} finally {
37+
await mongoose.connection.close();
38+
}
39+
})();

0 commit comments

Comments
 (0)