mongo Flashcards
mongo: To install and run mongo, type
brew install mongodb
mkdir -p /data/db
sudo chmod 777 /data/db
mongod
new terminal–
mongo
mongo: To show all databases, type
show dbs
mongo: To create a new db, type
use databaseName
mongo: A db will not show up in show dbs if
If there is not data in it
mongo: To see all collection form inside a db, type
show collections
mongo: To return only 10 documents from a collection, type
db.collectionName.find().limit(10)
mongo: In mongo a foreign key is called a
reference field
mongo: A reference field should contain
ObjectID(“string”)
mongo: To see the files in the current directory, type
ls()
mongo: To load data into mongo, type
load(“./file.js”)
pymongo: To get access to a database in mongodb, type
from pymongo import MongoClient
client = MongoClient(‘mongoURI’) # Find on mongolab
db = client.database_name
pymongo; To create a new collection, type
db.new_collection_name.insert_one({“key”:”value”})
pymongo: To easily insert a df into a mongo collection, type
from odo import odo
odo(df, db.collectionName)
ipython: To run normal shell commands inside a notebook, type
! before the command