mongo/funcs/crud_mongo.py
def delete(collection):
    """Delete 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']}
    del_result = collection.delete_one(prod_id)
    if del_result.deleted_count > 1:
        print('Item delect successfully.')
Delete an item selected by id.
Delete an item selected by id.
Delete an item selected by id .
def delete(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']}
    del_result = collection.delete_one(prod_id)
    if del_result.deleted_count > 1:
        print('Item delect successfully.')
def delete ( 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' ] } del_result = collection . delete_one ( prod_id ) if del_result . deleted_count > 1 : print ( 'Item delect successfully.' )
Delete an item selected by id.
Delete an item selected by id .
"""Delete an item selected by id."""
collection