December 2015
Beginner to intermediate
202 pages
4h
English
Many applications need to support the bulk importing of records. PyMongo makes this easy with the insert_many() method.
In order to insert multiple records, we need to first create a list of documents to insert, and then compile them into a single python list.
from pymongo import MongoClient client = MongoClient('localhost', 27017) db = client.pythonbicookbook customers = db.customers new_customers = [{"first_name": "Jane", "last_name": "Doe", "address_1": "123 12th Street NW", "address_2": "Suite 1200", "city": "Washington", "state": "DC", "zipcode": "20036", "interests": ["product_2", "product_3", "product_8"], "contact_requested": False, "created_at": datetime.datetime.utcnow(), ...Read now
Unlock full access