Removing white spaces from collection

db.users.find({},{ "firstName": 1 }).forEach(function(doc) {
doc.firstName = doc.firstName.trim();
db.users.update(
{ "_id": doc._id },
{ "$set": { "firstName": doc.firstName } }
);
})

db.users.find({},{ "lastName": 1 }).forEach(function(doc) {
doc.lastName = doc.lastName.trim();
db.users.update(
{ "_id": doc._id },
{ "$set": { "lastName": doc.lastName } }
);
})


db.users.find({},{ "fatherName": 1 }).forEach(function(doc) {
if(!!doc.fatherName){
doc.fatherName = doc.fatherName.trim();
db.users.update(
{ "_id": doc._id },
{ "$set": { "fatherName": doc.fatherName } }
);
}
})

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store