Beispiel #1
0
async def remove_dataset(path_to_dataset: str, out_dir: str, gmt_dir: str,
                         collection: pymongo.collection.Collection):

    dataset = collection.find_one({'selfPath': path_to_dataset})
    if dataset is not None:
        convert_folder = os.path.join(out_dir, dataset["token"])
        collection.delete_one({'selfPath': path_to_dataset})
        rm_rf(convert_folder)
        await modules_merger(out_dir, gmt_dir)
        logging.info(f"Successfully removed dataset {dataset['token']}")
Beispiel #2
0
def write_to_fomo(id: int, id_cursor: pymongo.collection.Collection, source: str):
    # check if it exists first
    record = exists_on_fomo(id, id_cursor)
    if record:
        if source == 'file':
            deleted_ids.append(id)
            id_cursor.delete_one({'id': id})
        if source == 'api':
            return id_cursor.update_one({'id': id}, {'$set': {'updated': datetime.datetime.utcnow()}})
    else:
        id_cursor.insert_one({"id": id, "updated": datetime.datetime.utcnow()})
def add_mdoc(coll: pymongo.collection.Collection, mdoc: dict):
    mdoc_filter = {"_id": mdoc["_id"]}

    current_mdoc_in_db = coll.find_one(mdoc_filter)

    if current_mdoc_in_db is not None:
        print(f"Stávanící mdokument '{mdoc['_id']}': {current_mdoc_in_db}")
        rewrite = input(f"'{mdoc['_id']}' mdokument už v kolekci existuje, mám ho přepsat (a/N)? ")
        if rewrite.lower() not in ["a", "ano", "y", "yes"]:
            print("Zachovávám původní mdokument.")
            return

        coll.delete_one(mdoc_filter)

    coll.insert_one(mdoc)
    print(f"Přidán mdokument {mdoc['_id']}")
Beispiel #4
0
def delete_item(collection: pymongo.collection.Collection,
                model: Union[Type[BaseModel], Type[dict]],
                old_item_id: Union[UUID, str],
                *,
                id_key: str = "id_",
                projection: dict = None,
                raise_exc: bool = True) -> bool:
    """
    Delete an item in the collection

    :param collection: Collection to query
    :param model: Class which the JSON in the collection represents
    :param old_item_id: UUID or name of item to delete
    :param id_key: If the UUID is stored outside of id_, specify here
    :param projection: Filter to exclude from mongo query result
    :param raise_exc: Whether to raise exception if item is not found.
    :return: Whether the item was deleted
    """
    old_item_json = get_item(collection, model, old_item_id, id_key=id_key, projection=projection, raise_exc=False)
    if old_item_json is None and raise_exc:
        raise problems.DoesNotExistException("delete", model.__name__, old_item_id)
    else:
        r = collection.delete_one(mongo_filter(model, old_item_id, id_key=id_key))

        return r.acknowledged
Beispiel #5
0
def delete_user(coll: pymongo.collection.Collection, user_id: ObjectId):
    assert isinstance(user_id, ObjectId)

    coll.delete_one({"_id": user_id})
Beispiel #6
0
def delete_meme(memes_collection: pymongo.collection.Collection, meme_id):
    memes_collection.delete_one({"_id": meme_id})
Beispiel #7
0
def delete_todo(todos_collection: pymongo.collection.Collection, todo_id):
    todos_collection.delete_one({"_id": ObjectId(todo_id)})