The MongoDB database is second only to HTML5 in the 10 skills required by software developers in the big data era, according to an authoritative survey. MongoDB is a document database based on Distributed file storage, which can be said to be a relational database in a non-relational (not only sql,nosql) database, with the features of free, simple, document-oriented storage, automatic sharding extensibility, and powerful query function. Better support for big data processing, designed to provide scalable, high-performance data storage solutions for Web applications. MongoDB stores data as a document and data structures consist of key-value pairs. A MongoDB document is similar to a JSON object. Field values can contain other documents, arrays, and document arrays.
MongoDB database can be downloaded to the official website, installation of the tutorial can be Baidu itself.
The Python extension library Pymongo perfectly supports the operation of MONGODB data and can be installed using the PIP command. The following code demonstrates part of the usage of the Pymongo operation of the MongoDB database, which can be used to learn more about using Python's tool, dir () and help (), or to consult the official MongoDB documentation.
1 ImportPymongo#Import Module2 3Client = Pymongo. Mongoclint ('localhost', 27017)#Connect to the database, 27017 is the default port4db = Client.students#Get Database5Db.collection_names ()#View a list of data collection names6Students = Db.students#Get Data collection7 Students.find ()8 9 forIteminchStudents.find ():#traversing DataTen Print(item) One Awangwu={'name':'Wangwu',' Age': 20,'Sex':'male'} -Students.insert (WANGWU)#Insert a record - forIteminchStudents.find ({'name':'Wangwu'}):#Specify query criteria the Print(item) - -Students.find_one ()#get a record -Students.find_one ({'name':'Wangwu'}) +Students.find (). Count ()#get Total Records -Students.remove ({'name':'Wangwu'})#Delete a record + AStudents.create_index (('name', Pymongo. Ascending))#Create an index at -Students.update ({'name':'Zhangsan'},{'$set':{' Age': 25}})#Update Database - -Students.remove ()#emptying the database - -Zhangsan ="' inLisi ="' -Wangwu ="' toStudents.insert_many ([Zhangsan,lisi,wangwu])#inserting more than one data + - forIteminchStudents.find (). Sort ('name', Pymongo. Ascending):#sort the results of a query the Print(item) *
8.3 Manipulating the MongoDB database