mongo/funcs/crud_mongo.py
def update(collection):
    """Update an item selected by id."""
    db_list = collection.find({})
    for idx, item in enumerate(db_list, start=1):
            print(len(item)*'-')
            print(idx, item)
    db_list = collection.find({})
    idx = int(input('Select the object to update by index: '))
    prod_id = {'_id': db_list[idx-1]['_id']}

    update_result = collection.update_one(prod_id, {'$set':
                    {input('Enter property name: '):
                     input('Enter new property value: ')}
                     })
    if update_result.modified_count == 1:
        print('Product name successfully updated.')

    else:
        print('No items have been updated.')
Update an item selected by id.
Update an item selected by id.
Update an item selected by id .
def update(collection):
    db_list = collection.find({})
    for idx, item in enumerate(db_list, start=1):
            print(len(item)*'-')
            print(idx, item)
    db_list = collection.find({})
    idx = int(input('Select the object to update by index: '))
    prod_id = {'_id': db_list[idx-1]['_id']}
    update_result = collection.update_one(prod_id, {'$set':
                    {input('Enter property name: '):
                     input('Enter new property value: ')}
                     })
    if update_result.modified_count == 1:
        print('Product name successfully updated.')
    else:
        print('No items have been updated.')
def update ( collection ) : db_list = collection . find ( { } ) for idx , item in enumerate ( db_list , start = 1 ) : print ( len ( item ) * '-' ) print ( idx , item ) db_list = collection . find ( { } ) idx = int ( input ( 'Select the object to update by index: ' ) ) prod_id = { '_id' : db_list [ idx - 1 ] [ '_id' ] } update_result = collection . update_one ( prod_id , { '$set' : { input ( 'Enter property name: ' ) : input ( 'Enter new property value: ' ) } } ) if update_result . modified_count == 1 : print ( 'Product name successfully updated.' ) else : print ( 'No items have been updated.' )
Update an item selected by id.
Update an item selected by id .
"""Update an item selected by id."""
collection