[#1789] remove all undefined pets once and for all

This commit is contained in:
Tyler Renelle 2013-11-17 21:17:58 -07:00
parent f64ca7d4d0
commit 30d6f6c4d8

View file

@ -0,0 +1,12 @@
// once and for all!
db.users.find({'items.pets':{$exists:1}},{'items.pets':1}).forEach(function(user){
_.reduce(user.items.pets, function(m,v,k){
if (!k.indexOf('undefined')) m.push(k);
return m;
}, []).forEach(function(key){
delete user.items.pets[key];
})
db.users.update({_id:user._id}, { $set:{'items.pets':user.items.pets} });
});