Help Center/ Document Database Service/ Developer Guide/ Application Development/ Python-based Development/ Complete Example
Updated on 2022-09-21 GMT+08:00
Complete Example
#!/usr/bin/python
import pymongo
import random
mongodbUri = 'mongodb://mongouser:thepasswordA1@10.66.187.127:27017/admin'
client = pymongo.MongoClient(mongodbUri)
db = client.somedb
db.user.drop()
element_num=10
for id in range(element_num):
name = random.choice(['R9','cat','owen','lee','J'])
sex = random.choice(['male','female'])
db.user.insert_one({'id':id, 'name':name, 'sex':sex})
content = db.user.find()
for i in content:
print i For more information about PyMongo APIs, see the official document.
Parent topic: Python-based Development
What is your overall rating for this page?
0
1
2
3
4
5
6
7
8
9
10
Very dissatisfiedVery satisfied
Thank you very much for your feedback. We will continue working to improve the documentation.
The system is busy. Please try again later.