Skip to content

Instantly share code, notes, and snippets.

@gmanolache
Created October 24, 2016 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gmanolache/3237d63044b94a84fb7004248b772464 to your computer and use it in GitHub Desktop.
Save gmanolache/3237d63044b94a84fb7004248b772464 to your computer and use it in GitHub Desktop.
Mongo Depth finder
db.users.find({
$where : function(){
var item = 'Location';
var value = '501';
var drillDown = function(obj){
for(var k in obj) {
if(typeof obj[k] == 'object' && obj[k] !== null){
if(drillDown(obj[k])) {
return true;
}
} else if(k == item && obj[k] == value) {
return true;
}
}
return false;
}
return drillDown(this);
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment