November 2017
Intermediate to advanced
342 pages
9h 9m
English
The Python driver provides methods for CRUD just like Ruby and PHP. Following on from Chapter 2, Schema Design and Data Modeling, and the books variable that points to our books collection, we can have:
from pymongo import MongoClientfrom pprint import pprint>>> book = { 'isbn': '301', 'name': 'Python and MongoDB', 'price': 60}>>> insert_result = books.insert_one(book)>>> pprint(insert_result)<pymongo.results.InsertOneResult object at 0x104bf3370>>>> result = list(books.find())>>> pprint(result)[{u'_id': ObjectId('592149c4aabac953a3a1e31e'), u'isbn': u'101', u'name': u'Mastering MongoDB', u'price': 30.0, u'published': datetime.datetime(2017, 6, 25, 0, 0)},{u'_id': ObjectId('59214bc1aabac954263b24e0'), u'isbn': u'102', u'name': ...Read now
Unlock full access