Skip to content

Instantly share code, notes, and snippets.

@tomasbedrich
Last active September 3, 2019 10:55
Show Gist options
  • Save tomasbedrich/9eeefd280bbf00473569886e25399ad6 to your computer and use it in GitHub Desktop.
Save tomasbedrich/9eeefd280bbf00473569886e25399ad6 to your computer and use it in GitHub Desktop.
MongoDB Docker JSON analysis

Create temporary MongoDB Docker container (named some-mongo) and fill it with JSON data from data subdir in current working directory. The documents are placed in tmp DB, tmp collection.

docker run -p 27017:27017 -v $(pwd)/data:/import --name some-mongo -d mongo
docker exec -ti some-mongo bash -c "for f in /import/*; do mongoimport --jsonArray --db tmp --collection tmp --file \$f; done"
from pymongo import MongoClient
client = MongoClient()
db = client.tmp
print(db.tmp.find_one())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment