mongodb script to remove bad study chapter nodes

pull/4785/head
Thibault Duplessis 2018-12-14 09:49:07 +08:00
parent e8eb335209
commit a85ef9cfaf
1 changed files with 22 additions and 0 deletions

View File

@ -0,0 +1,22 @@
var studyId = '0Obg93mv';
function dig(chapId, node, path) {
for (var i in node.n) {
var c = node.n[i];
var newPath = `${path}.n.${i}`;
if (!c || !c.i) {
var set = {};
set[`${path}.n`] = [];
printjson(set);
db.study_chapter.update({_id:chapId},{$set:set});
}
else {
dig(chapId, c, newPath);
}
}
}
db.study_chapter.find({studyId: studyId}).forEach(chap => {
print(`${studyId}/${chap._id}`);
dig(chap._id, chap.root, 'root');
});