relational database nouns vs. MongoDB:
relational database |
Mongodb |
Database |
Database |
Table |
Collection |
Row |
Document |
Index |
Index |
Join |
Lookup |
Foreign Key |
Reference |
multi-table Transaction |
Single Document transaction |
The command line uses MongoDB
Insert your First Data
> Show Databases
Local 0.000GB
> Use test #切换到test数据库, if not, create a new
Switched to DB test
> Show Databaseslocal 0.000GB
> Db.demo.insert ({"Key": "Value"}) Writeresult ({"ninserted": 1})
> Show databaseslocal 0.000GBtest 0.000GB
> Show Collectionsdemo
> Db.demo.findOne () {"_id": ObjectId ("573af7085ee4be80385332a6"), "key": "Value"}
Using MongoDB in Python
Import pymongo## client defaults to localhost and port 27017. eg mongoclient (' localhost ', 27017) Client = pymongo. Mongoclient () #连接到本地数据库blogDatabase = client[ "blog" ] # Switch to the blog database userscollection = blogdatabase[ "users" ] # Switch to Userscollectionuserscollection.insert_one ( { "username" : "jdrumgoole", "Password" : "Top secret", "Lang" : "EN"  }) #插入一条数据user = userscollection.find_one () # Find the latest piece of data print ( user ) articlescollection = blogdatabase[ "articles" ]author = "Jdrumgoole" article = { "title" : "this is my first " Post "," Body " : " The is the longer body text for my blog post. we can add lots of text here. "," author" : author," tags " : [ " Joe ", " General ", " Ireland ", " admin " ]}## lets check if our author exists#if userscollection.find_one ( { " Username " : AUTHOR }) :articlescollection.insert_one ( article ) else:raise ValueError ( "Author %s does not exist" % author )
This article is from the "Danielqu" blog, make sure to keep this source http://qujunorz.blog.51cto.com/6378776/1858528
MongoDB Common operations