No project description provided
Project description
pymongoの単純なラッパー。接続情報、db_name、collection_nameをまとめてdictに含めることでDB操作のコードをシンプルにする。
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)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
moncoll2-0.1.0.tar.gz
(4.0 kB
view details)
Built Distribution
File details
Details for the file moncoll2-0.1.0.tar.gz
.
File metadata
- Download URL: moncoll2-0.1.0.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.4 CPython/3.8.12 Darwin/18.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7cd56dc3a45b75c0406b38a71fdd5fbff4fff4a107837cefb8e4079487e55da |
|
MD5 | 3f7edc8eca06e9a1d4bf8e9b5cc50359 |
|
BLAKE2b-256 | fb60b1833876f619d30b920be9ae5b7be34d2214b2ef79e8fcd5a0ae7687df9a |
File details
Details for the file moncoll2-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: moncoll2-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.4 CPython/3.8.12 Darwin/18.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b008a407efcee92bd8793b8e70cb2b0d565a581fcd01613664642c69c368934 |
|
MD5 | ed27f8f35ee20e19d2baa5b51117b34d |
|
BLAKE2b-256 | 3ab60e7610809f3b4f33a3c76f58b64df8231dfa10a02ff68d7bb2ef1b9882df |