View the step-by-step solution to:

I think I need to input this in codio:

I need help using pymongo in codio.


I think I need to input this in codio:


Example Python Code to Insert a Document

import json from bson

import json_util from pymongo

import MongoClient connection = MongoClient('localhost', 27017)

db = connection['myDB']

collection = db['myCollection']

def insert_document(document):

try:

result=collection.save(document)

except ValidationError as ve:

abort(400, str(ve))

return result


def main():

myDocument = { "keyName" : "test value data"}

print insert_document(myDocument)


main() 


When I do it brings an error for the line ..... except ValidationError as ve:


I also need to do the following:


Develop a function that will make a document in the MongoDB database "city" in the collection "inspections." Be sure it can handle error conditions gracefully.

a. Input -> argument to function will be set of key/value pairs in the data that is acceptable to the MongoDB driver insert API call

b. return -> True if successful insert else False

Recently Asked Questions

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question