Ejemplo n.º 1
0
def update(db, documents):
    try:
        start_c = time.clock()
        start_t = time.time()

        for document in documents:
            doc = db[document]
            doc["author"] = generator.generate_word(constants.number_of_letters)
            db[doc.id] = doc

        elapsed_c = time.clock() - start_c
        elapsed_t = time.time() - start_t
        message = (
            "--> "
            + str(len(documents))
            + " updated document(s).\n "
            + "Time: "
            + str(elapsed_c)
            + " seconds process time and "
            + str(elapsed_t)
            + " seconds real time.\n"
        )
        print message
    except Exception, e:
        print e
        print "--> Error updating document(s)."
Ejemplo n.º 2
0
def update(db, documents, message):
    try:
        start_c = time.clock()
        start_t = time.time()
        for document in documents:
            db.posts.update({"author": document['author']}, {                    
                              "author": "Updated post! " + str(document['author']) ,
                              "text": generator.generate_word(constants.number_of_letters),
                              "tags": ["mongodb", "python", "pymongo"],
                              "date": datetime.datetime.utcnow(),
                              "category": {
                                "name": generator.generate_word(constants.number_of_letters),
                                "description": generator.generate_word(constants.number_of_letters)
                              }
                            })
        elapsed_c = (time.clock() - start_c)
        elapsed_t = (time.time() - start_t)   
        if message == True:
            print "--> " + str(len(documents)) + " updated document(s).\n " + "Time: " + str(elapsed_c) + " seconds process time and " + str(elapsed_t) + " seconds real time.\n"           
    except Exception:
        print "--> Error updating document(s)."