Skip to content

Instantly share code, notes, and snippets.

@ufo22940268
Last active June 5, 2018 02:24
Show Gist options
  • Select an option

  • Save ufo22940268/0207bb47486041a6787c7e58d0f4556e to your computer and use it in GitHub Desktop.

Select an option

Save ufo22940268/0207bb47486041a6787c7e58d0f4556e to your computer and use it in GitHub Desktop.
Find with any key in mongo shell
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))
}
}
}
@ufo22940268
Copy link
Copy Markdown
Author

ufo22940268 commented Jun 5, 2018

Example

findAny('orders', "34939380726466")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment