MongoDB Simple to use

Source: Internet
Author: User
//python1.连接client=pymongo.MongoClient("localhost", 27017)2.#获取数据库 testdb=client.test3.#获取数据库集合stu=db.stu4.打印集合个数print(stu.count())5.插入s1 = {‘name‘: ‘allen‘, ‘age‘: 18}#查获取ids1_id = stu.insert_one(s1).inserted_id6.打印 idprint(s1_id)7.查找一行temp=stu.find_one(s1) print(temp) //print(type(temp)) <class ‘dict‘>{‘_id‘: ObjectId(‘5ae034dc1d41c8293e8dec8d‘), ‘name‘: ‘allen‘, ‘age‘: 18}8.查找所有print(stu.find(s2)) //注意在 python 中返回的是对象<class ‘pymongo.cursor.Cursor‘>9.对象转成 listprint(list(stu.find())) //stu是个集合

MongoDB Simple to use

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.