def insert_autos(infile, db): autos = process_file(infile) # Your code here. Insert the data in one command # autos will be a list of dictionaries, as in the example in the previous video # You have to insert data in a collection 'autos' [db.autos.insert(e) for e in autos]
def test(): data = process_file(DATAFILE, FIELDS) print "Your first entry:" pprint.pprint(data[0]) first_entry = { "synonym": None, "name": "Argiope", "classification": { "kingdom": "Animal", "family": "Orb-weaver spider", "order": "Spider", "phylum": "Arthropod", "genus": None, "class": "Arachnid" }, "uri": "http://dbpedia.org/resource/Argiope_(spider)", "label": "Argiope", "description": "The genus Argiope includes rather large and spectacular spiders that often have a strikingly coloured abdomen. These spiders are distributed throughout the world. Most countries in tropical or temperate climates host one or more species that are similar in appearance. The etymology of the name is from a Greek name meaning silver-faced." } assert len(data) == 76 assert data[0] == first_entry assert data[17]["name"] == "Ogdenia" assert data[48]["label"] == "Hydrachnidiae" assert data[14]["synonym"] == ["Cyrene Peckham & Peckham"]
def insert_autos(infile, db): autos = process_file(infile) #num_autos = db.autos.find().count() #print "num_autos before insert:", num_autos for each in autos: db.autos.insert(each)
def write_to_json(infile, json_file): data = process_file(infile) # write item by item with open(json_file, "w") as jf: for a in data: json.dump(a, jf, indent=2) jf.write("\n") """
def insert_autos(infile, db): autos = process_file(infile) db.autos.insert(autos)
def insert_autos(infile, db): autos = process_file(infile)
from autos import process_file from pymongo import MongoClient from pprint import pprint client = MongoClient("mongodb://localhost:27017") db = client.uda # def insert_autos(infile, db): # Add your code here. Insert the data in one command. if __name__ == "__main__": # Code here is for local use on your own computer. data = process_file('small_autos.csv') pprint(data) db.autos.insert(data) # insert_autos('small_autos.csv', db) pprint(db.autos.find_one())
def insert_autos(infile, db): data = process_file(infile) for a in data: # a is a dictionary db.autos.insert(a) # question: difference between inserting a and data
from autos import process_file from pymongo import MongoClient client = MongoClient("mongodb://localhost:27017") db = client.examples col = db.autos autos = process_file('autos.csv') col.insert(autos)
def insert_autos(infile, db): data = process_file(infile) # Add your code here. Insert the data in one command. db['autos'].insert(data)
def insert_autos(infile, db): data = process_file(infile) # Insert the data in one command. # pprint.pprint(data) db.autos.insert(data)
def insert_autos(infile, db): data = process_file(infile) # Add your code here. Insert the data in one command. # nothing_list = [db.autos.insert(item) for item in data] db.autos.insert(data)
def insert_autos(infile, db): data = process_file(infile) for a in data: db.autos.insert(a)
def insert_autos(infile, db): data = process_file(infile)
def insert_autos(infile, db): autos = process_file(infile) for a in autos: db.autos.insert(a)
def insert_autos(infile, db): autos = process_file(infile) # Your code here. Insert the data in one command for a in autos: db.autos.insert(a)
def insert_autos(infile, db): data = process_file(infile) # Add your code here. Insert the data in one command. db.autos.insert(data)
def insert_autos(infile, col): autos = process_file(infile) col.insert_many(autos)
def insert_autos(infile, db): data = process_file(infile) # Add your code here. Insert the data in one command. for a in data: db.autos.insert_one(a)
def insert_autos(infile, db): data = process_file(infile) db.autos.insert(data)
def insert_autos(infile, db): data = process_file(infile) pdb.set_trace() for mongo_row in data: db.autos.save(mongo_row)
def insert_autos(infile, db): data = process_file(infile) for car in data: db.autos.insert(car)
__author__ = "Miller" from autos import process_file from pymongo import MongoClient client = MongoClient("mongodb://localhost:27017") db = client.examples col = db.autos autos = process_file("autos.csv") col.insert(autos)