Cette page n'est pas encore disponible dans votre langue. Nous nous efforçons d'ajouter d'autres langues. Nous vous remercions de votre compréhension.

On this page

Show all

Complete Example

Updated on 2022-09-21 GMT+08:00
#!/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.

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback