No project description provided
Project description
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)
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file moncoll2-0.2.0.tar.gz.
File metadata
- Download URL: moncoll2-0.2.0.tar.gz
- Upload date:
- Size: 3.9 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 |
0d38720bf78d91a914658a15425283b3c69d1d8e3931d7efd26b01ce6f5d7ca3
|
|
| MD5 |
8578224742689f4b8f4bf0cfb9bc3986
|
|
| BLAKE2b-256 |
3e26145b37795cb069bda60e2545764a62215d58d8516e5f8e9fde79d1afb9ce
|
File details
Details for the file moncoll2-0.2.0-py3-none-any.whl.
File metadata
- Download URL: moncoll2-0.2.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 |
b46167bdcfd0d13fad4562e19e468210a28c27c9ff4286422761ce93815e8190
|
|
| MD5 |
4818e5fcd2b1b042235b847e40afd893
|
|
| BLAKE2b-256 |
25906c07edf1e33e97122704fe979b188f48a3e96f363be50f173a8045069002
|