python 与 mongodb的交互--更新操作
                        
                            时间:2021-07-01 10:21:17
                            帮助过:4人阅读
							                        
                     
                    
                    
                     from pymongo 
import * 
 2 def insert_func():
 3     try:
 4         client_obj= MongoClient(port=27017,host=
‘localhost‘)
 5         db =
 client_obj.test
 6         #执行插入操作
 7         db.insert_one({
‘name‘:
‘mary‘,
‘age‘:15
})
 8         #插入多条
 9         db.insert_many([{
‘name‘:
‘jimy‘,
‘age‘:18},{
‘name‘:
‘alen‘,
‘age‘:20
}])
10         #插入多条或者插入一条都可以用inert
11         #db.insert({})
12         #db.insert([{},{}])
既然插入多条和插入一条都可以使用insert插入,那么还要什么insert_one   & insert_many 呢?
查阅源代码我们可以看到原因:

对于大神们的深层次远见原谅我现在还没有看到。 只看到一条warning : 不建议使用insert 。 
也许在 业务领域多元化需求下 我们会发现该设计的应用场景。
python 与 mongodb的交互--更新操作
标签:--   imp   span   建议   style   业务   img   需求   logs