prøv dette
const remove = (data) => {
for (let key in data) {
const val = data[key];
if (val == null) {
delete data[key];
} else if (Array.isArray(val)) {
val.forEach((v) => {
remove(v);
});
}
}
return data;
}
db.getCollection('Collection').find({}).forEach((data) => {
data = remove(data);
db.getCollection('OtherCollection').insert(data);
//db.getCollection('Collection').save(data); // update same record
print(data);
})