-
-
Save sgoel/6598976 to your computer and use it in GitHub Desktop.
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( Object.prototype.toString.call(obj[key]) === '[object Object]' ) { | |
new_array = []; | |
for ( objkey in obj[key] ) { | |
new_array.push(obj[key][objkey]); | |
} | |
obj[key] = new_array; | |
} else { | |
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