pymongoの単純なラッパー。接続情報、db_name、collection_nameをまとめてdictに含めることでDB操作のコードをシンプルにする。
Install
pip install moncoll2
Useit
MC(settings: dict)-> pymongo.collection.Collection
settingsを元にしてcollectionを返す。with構文の中で操作をする事によってDBのcloseを確実に行う。
from moncoll2 import MC
settings = {
"username": "testuser",
"password": "testpass",
"host": "192.168.0.99",
"port": 12345,
"coll_name": "test_collenction",
"db_name": "test_db"
}
with MC(settings) as coll:
assert coll.full_name == 'test_db.test_collenction'
coll.insert_one({"a": 1})
res = coll.find_one()
assert res['a'] == 1
coll.drop()
Args
settings (dict): pymongoのMongoClientに渡す引数にdb_nameとcollection_nameを加えたもの
mongo_client – Tools for connecting to MongoDB — PyMongo 4.0.1 documentation
to_bulklist(_list: list, idname: str = "_id") -> list:
listをbulk_writeで使用できる形式にする
Args
_list (list): 元になるlist idname (str): _idになる項目名、元になるlistに含まれるなら省略可能
Returns
list: bulk_writeで使用できる形式のlist
Raises
BulkItemNotIdError: 元のlistに_idという項目が含まれておらず、かつ引数idnameが指定されていない場合に発生
Examples:
>>> li = [
... {"name": "Karin", "gender": "female"},
... {"name": "Decker", "gender": "male"}
... ]
>>> res = to_bulklist(li, 'name')
>>> res[0]
UpdateOne({'_id': 'Karin'}, {'$set': {'name': 'Karin', 'gender': 'female', '_id': 'Karin'}}, True, None, None, None)
Metadata
Release files for moncoll2 0.2.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 |
|---|---|---|---|---|
| moncoll2-0.2.0.tar.gz | 3.9 kB | Without provenance | Details for moncoll2-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| moncoll2-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for moncoll2-0.2.0-py3-none-any.whl |
Total release size: 8.0 kB
Release files / moncoll2-0.2.0.tar.gz
| Download URL | moncoll2-0.2.0.tar.gz |
|---|---|
| Size | 3.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0d38720bf78d91a914658a15425283b3c69d1d8e3931d7efd26b01ce6f5d7ca3
|
|
BLAKE2b-256 checksum How to use checksums |
3e26145b37795cb069bda60e2545764a62215d58d8516e5f8e9fde79d1afb9ce
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.4 CPython/3.8.12 Darwin/18.7.0
|
Release files / moncoll2-0.2.0-py3-none-any.whl
| Download URL | moncoll2-0.2.0-py3-none-any.whl |
|---|---|
| Size | 4.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b46167bdcfd0d13fad4562e19e468210a28c27c9ff4286422761ce93815e8190
|
|
BLAKE2b-256 checksum How to use checksums |
25906c07edf1e33e97122704fe979b188f48a3e96f363be50f173a8045069002
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.4 CPython/3.8.12 Darwin/18.7.0
|
Security for moncoll2 0.2.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.