Last active
June 5, 2018 02:24
-
-
Save ufo22940268/0207bb47486041a6787c7e58d0f4556e to your computer and use it in GitHub Desktop.
Find with any key in mongo shell
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 findAny(collection, value) { | |
var cursor = db[collection].find() | |
while (cursor.hasNext()) { | |
var o = cursor.next() | |
if (Object.keys(o).filter(key => o[key] == value).length) { | |
print(tojson(o)) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example