Last active
December 23, 2015 06:59
-
-
Save bri-bri/6597826 to your computer and use it in GitHub Desktop.
For Sachin.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function convertObjectKeyToArray(obj,key) { | |
if( obj.hasOwnProperty(key) ) { | |
if( obj[key].constructor == Object ) { | |
new_array = []; | |
for ( objkey in obj[key] ) { | |
new_array.push(obj[key][objkey]); | |
} | |
obj[key] = new_array; | |
} else if(obj[key].constructor != Array ) { | |
print("{" + obj._id + "} has type " + typeof obj[key]+ " for key: " + key ); | |
} | |
} | |
return obj; | |
} | |
// Example useage. | |
db.profiles.find().forEach( function( profile ) { | |
new_profile = convertObjectKeyToArray(profile,"INSERT SEARCH KEY"); | |
if( new_profile != null ){ | |
db.profiles.save(new_profile); | |
} else { | |
print ("{"+profile._id+"} had a problem."); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment