※ collection 객체의 insert_many() 메서드 이용.
import pymongo
myclient = pymongo.MongoClient('mongodb://localhost:27017/')
mydb = myclient['hz']
mycol = mydb["hz_member"]
mylist = [
{ "_id": 1, "mb_name": 'AAA', "mb_level": '1'},
{ "_id": 2, "mb_name": 'BBB', "mb_level": '2'},
{ "_id": 3, "mb_name": 'CCC', "mb_level": '2'},
{ "_id": 4, "mb_name": 'DDD', "mb_level": '3'},
{ "_id": 5, "mb_name": 'EEE', "mb_level": '3'},
{ "_id": 6, "mb_name": 'FFF', "mb_level": '3'},
{ "_id": 7, "mb_name": 'GGG', "mb_level": '4'},
{ "_id": 8, "mb_name": 'HHH', "mb_level": '4'},
{ "_id": 9, "mb_name": 'III', "mb_level": '4'},
{ "_id": 10, "mb_name": 'JJJ', "mb_level": '4'},
{ "_id": 11, "mb_name": 'KKK', "mb_level": '5'},
{ "_id": 12, "mb_name": 'LLL', "mb_level": '5'},
{ "_id": 13, "mb_name": 'MMM', "mb_level": '5'},
{ "_id": 14, "mb_name": 'NNN', "mb_level": '5'}
]
x = mycol.insert_many(mylist)
print(x.inserted_ids)
결과값: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
최신댓글