install
pip install link-mongodb
Usage
import os
from link_mongodb import core
from typing import Optional, List, Dict, Any
from dotenv import load_dotenv
load_dotenv()
mongodb_uri = f'mongodb://{os.getenv("MONGODB_USER")}:{os.getenv("MONGODB_PASSWORD")}@{os.getenv("MONGODB_HOST")}:{os.getenv("MONGODB_PORT")}/?authMechanism=DEFAULT'
database_name = os.getenv("APP_NAME") + os.getenv("MONGODB_DATABASE_NAME")
def find_one(collection_name : str,filter : dict) -> Optional[Dict]:
result = core.find_one(mongodb_uri,database_name,collection_name,filter)
# None
# {'_id': ObjectId('654f49d2cc57188a2d539e72'), 'key': 'value'}
return result
def find_all(collection_name : str,filter : dict) -> Optional[List]:
result = core.find_all(mongodb_uri,database_name,collection_name,filter)
# []
# [{'_id': ObjectId('654f4beacc57188a2d539e74'), 'key': 'values'}]
# [{'_id': ObjectId('654f49d2cc57188a2d539e72'), 'key': 'value'}, {'_id': ObjectId('654f4b1ecc57188a2d539e73'), 'key': 'value', 'key2': 'value2'}]
return result
def insert_one(collection_name : str,filter : dict) -> Optional[Dict]:
result = core.insert_one(mongodb_uri,database_name,collection_name,filter)
# {'_id': ObjectId('654f51a59543b75c7cf4ca51'), 'key3': 'value1'}
return result
def insert_many(collection_name : str,document : list) -> Optional[List]:
result = core.insert_many(mongodb_uri,database_name,collection_name,document)
# [ObjectId('654f58aad70e1f8cccc7e7ff'), ObjectId('654f58aad70e1f8cccc7e800')]
return result
def update_one(collection_name : str,filter : dict,update : dict) -> Optional[Dict]:
result = core.update_one(mongodb_uri,database_name,collection_name,filter,update)
# {'n': 0, 'nModified': 0, 'ok': 1.0, 'updatedExisting': False}
# {'n': 1, 'nModified': 1, 'ok': 1.0, 'updatedExisting': True}
return result
def update_many(collection_name : str,filter : dict,update : dict) -> Optional[Dict]:
result = core.update_many(mongodb_uri,database_name,collection_name,filter,update)
# {'n': 3, 'nModified': 0, 'ok': 1.0, 'updatedExisting': True}
# {'n': 3, 'nModified': 2, 'ok': 1.0, 'updatedExisting': True}
return result
def delete_one(collection_name : str,filter : dict) -> Optional[Dict]:
result = core.delete_one(mongodb_uri,database_name,collection_name,filter)
# {'n': 0, 'ok': 1.0}
# {'n': 1, 'ok': 1.0}
return result
def delete_many(collection_name : str,filter : dict) -> Optional[Dict]:
result = core.delete_many(mongodb_uri,database_name,collection_name,filter)
# {'n': 0, 'ok': 1.0}
# {'n': 3, 'ok': 1.0}
return result
def count(collection_name : str,filter : dict) -> Optional[Any]:
result = core.count(mongodb_uri,database_name,collection_name,filter)
# 0
# 2
return result
def random_valuve(collection_name : str,key_name : str) -> Optional[Any]:
result = core.random_valuve(mongodb_uri,database_name,collection_name,key_name)
# 64ca01272ec39bc754bb202f
return result
def download_file(file_id : str) -> Optional[Any]:
result = core.download_file(mongodb_uri,database_name,file_id)
return result
# if __name__ == "__main__":
# collection = 'collection'
# filter = {"key":"value"}
# result = find_one(collection,filter)
# print(result)
# collection = 'collection'
# filter = {"key":"values"}
# find_all(collection,filter)
# collection = 'collection'
# document = {"key":"value"}
# insert_one(collection,document)
# collection = 'collection'
# document = [{"key":"value"},{"key":"value2"},{"key":"value3"}]
# result = insert_many(collection,document)
# print(result)
# collection = 'collection'
# filter = {"key":"value"}
# document = {"key":"value1"}
# update_one(collection,filter,{'$set':document})
# collection = 'collection'
# filter = {"key":"value"}
# document = {"ddd":"change"}
# result = update_many(collection,filter,{'$set':document})
# print(result)
# collection = 'collection'
# filter = {"key":"value2"}
# result = delete_one(collection,filter)
# print(result)
# collection = 'collection'
# filter = {"key":"value"}
# result = delete_many(collection,filter)
# print(result)
# collection = 'collection'
# result = count(collection,{"key":"value"})
# print(result)
Metadata
Release files for link-mongodb 2.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| link_mongodb-2.0.0.tar.gz | 5.7 kB | Without provenance | Details for link_mongodb-2.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| link_mongodb-2.0.0-py3-none-any.whl | Python 3 | none | any | Details for link_mongodb-2.0.0-py3-none-any.whl |
Total release size: 10.4 kB
Release files / link_mongodb-2.0.0.tar.gz
| Download URL | link_mongodb-2.0.0.tar.gz |
|---|---|
| Size | 5.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
78978cc7f62814b1f5617c4e591d9c51ecc41b1647304fc63e5add72c44c6295
|
|
BLAKE2b-256 checksum How to use checksums |
4cb69d3458ee19e3c326a0face7cc39dff6cb21220b6c8e1aedb132c1f8ccecd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.11.7
|
Release files / link_mongodb-2.0.0-py3-none-any.whl
| Download URL | link_mongodb-2.0.0-py3-none-any.whl |
|---|---|
| Size | 4.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e5347f17e9d0227d8e64bd462d85de781ee144004221341a8dafcb1a62947f6f
|
|
BLAKE2b-256 checksum How to use checksums |
f04edf48921fdd097cc4d0bcc24515f20ba76d52ea3e01902a5125034e4ce5a0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.11.7
|
Security for link-mongodb 2.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.