Skip to content

Instantly share code, notes, and snippets.

@dsaiztc
Last active August 29, 2015 14:24
Show Gist options
  • Save dsaiztc/028bfcd6846785c2b019 to your computer and use it in GitHub Desktop.
Save dsaiztc/028bfcd6846785c2b019 to your computer and use it in GitHub Desktop.
// cd <mongodb installation dir>
// ./bin/mongo
db // display database in use (default database: test)
show dbs // Show all databases
use <database> // select database to use
// Access a collection and use shell methods
show collections // show all collections for current database
db.<collection>.find()
db["3test"].find()
db.getCollection("3test").find()
db.<collection>.find().pretty()
# To run MongoDB just type:
mongod --dbpath ~/Development/MongoDB/db/
# Import a JSON document
mongoimport -d dbname -c collectionname --file input-file.json
# Import a 'JSON Lines' document (one JSON document per file) into MongoDB http://jsonlines.org/
mongoimport -d dbname -c collectionname --file input-file.jsonl
# Import a valid JSON document (in case we have several documents)
mongoimport --db <db-name> --collection <coll-name> --type json --file seed.json --jsonArray
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment