From 7479357869099d1c4c6f57961f6ce22028736355 Mon Sep 17 00:00:00 2001 From: Scott Erickson Date: Thu, 28 Apr 2016 13:47:03 -0700 Subject: [PATCH] Tweak course population script --- ...016-04-14-populate-classrooms-with-levels.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/scripts/mongodb/migrations/2016-04-14-populate-classrooms-with-levels.js b/scripts/mongodb/migrations/2016-04-14-populate-classrooms-with-levels.js index 83855682c..df5e8e3e0 100644 --- a/scripts/mongodb/migrations/2016-04-14-populate-classrooms-with-levels.js +++ b/scripts/mongodb/migrations/2016-04-14-populate-classrooms-with-levels.js @@ -26,9 +26,14 @@ for (var courseIndex in courses) { print('constructed', JSON.stringify(coursesData, null, '\t')); -db.classrooms.update( - {}, // Set all - //{courses: {$exists: false}}, // Set all w/out values - {$set: {courses: coursesData}}, - {multi: true} -); \ No newline at end of file +db.classrooms.find({}, {courses:1}).forEach(function(classroom) { + print('classroom', classroom._id); + if(classroom.courses) { + print('\tskipping'); + return; + } + db.classrooms.update( + {_id: classroom._id}, + {$set: {courses: coursesData}} + ); +});