8.3 Manipulating the MongoDB database

Source: Internet
Author: User
Tags mongodb documentation

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.