Inserting a single record using PyMongo

In order to produce actionable insights from your business intelligence system, you will more than likely need to combine data sources. Let us say that you have

Getting ready

In order to insert a record, we first create the record and then insert it. The new record needs to be in the JSON format.

How to do it…

from pymongo import MongoClient client = MongoClient('localhost', 27017) db = client.pythonbicookbook customers = db.customers import datetime new_customer = {"first_name": "Bob", "last_name": "Smith", "address_1": "123 Main Street", "address_2": "Suite 200", "city": "Washington", "state": "DC", "zipcode": "20036", "interests": ["product_1", "product_4", "product_7"], "contact_requested": True, "created_at": ...

Get Python Business Intelligence Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.