在数据库中创建数据库.表,插入数据. from pymongo import MongoClient host = "localhost" port = 27017 client = MongoClient(host, port) db = client['test'] sheet = db['sheet'] for i in range(1001): print(i) sheet.instert_one( { 'name': 'name'+ str(i), 'age': i, })
在mongo中,有一个命令非常的方便,就是upsert,顾名思义就是update+insert的作用 根据条件判断有无记录,有的话就更新记录,没有的话就插入一条记录 upsert的使用方法: MongoDB shell version: connecting to: test > use date switched to db date , "sex":"male"}) , "sex":"male"}) , "
系统转移过程中,擅自把aptitude安装的mongoengine换成了pip安装,系统启动以后,报这个错误 报错提示: File "/usr/local/lib/python2.7/dist-packages/pymongo/mongo_client.py", line 748, in _socket_for_reads with self._get_socket(read_preference) as sock_info: File "/usr/lib/python2.7