Created
October 24, 2016 09:01
-
-
Save gmanolache/3237d63044b94a84fb7004248b772464 to your computer and use it in GitHub Desktop.
Mongo Depth finder
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
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