codecombat/scripts/mongodb/updateCourses.js

64 lines
2 KiB
JavaScript
Raw Normal View History

2015-08-29 10:15:35 -04:00
// Update course data
// Usage:
// mongo <address>:<port>/<database> <script file> -u <username> -p <password>
// NOTE: uses name as unique identifier, so changing the name will insert a new course
// NOTE: pricePerSeat in USD cents
2015-08-29 10:15:35 -04:00
2015-09-10 13:37:32 -04:00
var courses =
2015-08-29 10:15:35 -04:00
[
{
name: "Introduction to Computer Science",
slug: "introduction-to-computer-science",
campaignID: ObjectId("55b29efd1cd6abe8ce07db0d"),
concepts: ['basic_syntax', 'arguments', 'while_loops', 'strings', 'variables'],
description: "Learn basic syntax, while loops, and the CodeCombat environment.",
2015-09-10 13:37:32 -04:00
duration: NumberInt(1),
pricePerSeat: NumberInt(0),
2015-08-29 10:15:35 -04:00
screenshot: "/images/pages/courses/101_info.png"
},
{
name: "Computer Science 2",
slug: "computer-science-2",
campaignID: ObjectId("55b29efd1cd6abe8ce07db0d"),
concepts: ['basic_syntax', 'arguments', 'while_loops', 'strings', 'variables', 'if_statements'],
description: "Introduce Arguments, Variables, If Statements, and Arithmetic.",
2015-09-10 13:37:32 -04:00
duration: NumberInt(5),
pricePerSeat: NumberInt(400),
screenshot: "/images/pages/courses/102_info.png"
},
{
name: "Computer Science 3",
slug: "computer-science-3",
campaignID: ObjectId("55b29efd1cd6abe8ce07db0d"),
concepts: ['if_statements', 'arithmetic'],
description: "Learn how to handle input.",
2015-09-10 13:37:32 -04:00
duration: NumberInt(5),
pricePerSeat: NumberInt(400),
screenshot: "/images/pages/courses/103_info.png"
2015-08-29 10:15:35 -04:00
}
];
print("Finding course concepts..");
for (var i = 0; i < courses.length; i++) {
var concepts = {};
var cursor = db.campaigns.find({_id: courses[i].campaignID}, {'levels': 1});
if (cursor.hasNext()) {
var doc = cursor.next();
for (var levelID in doc.levels) {
for (var j = 0; j < doc.levels[levelID].concepts.length; j++) {
concepts[doc.levels[levelID].concepts[j]] = true;
}
}
}
courses[i].concepts = Object.keys(concepts);
}
print("Updating courses..");
2015-09-10 13:37:32 -04:00
for (var i = 0; i < courses.length; i++) {
db.courses.update({name: courses[i].name}, courses[i], {upsert: true});
2015-08-29 10:15:35 -04:00
}
print("Done.");