使用方便的实用程序和乐趣访问 mongodb
项目描述
小丑-mongodb
使用方便的实用程序和乐趣访问 mongodb。
使用 MongoInterface 连接到多个 mongo 服务器
例子:
GlobalInterface
定义example/environ.py
为:
from functools import cached_property
import volkanic
from joker.mongodb.interfaces import MongoInterface
class GlobalInterface(volkanic.GlobalInterface):
package_name = 'example'
default_config = {
"mongoi": {
"local": {},
"remote": {
"host": "192.168.22.122",
"port": 27017
}
}
}
@cached_property
def mongoi(self) -> MongoInterface:
return MongoInterface.from_config(self.conf['mongoi'])
如果在以下位置之一找到配置文件:
- 在开发环境中的项目目录下
~/.example/config.json5
/etc/example/config.json5
/example/config.json5
它将覆盖GlobalInterface.default_config
.
代码中的用法example/application.py
:
from bson import ObjectId
# noinspection PyUnresolvedReferences,PyPackageRequirements
from example.environ import GlobalInterface
gi = GlobalInterface()
def get_product(product_oid):
coll = gi.mongoi.get_coll('remote', 'example', 'products')
return coll.find_one({'_id': ObjectId(product_oid)})
if __name__ == '__main__':
print(get_product('60f231605e0a4ea3c6c31c13'))
近期变动
版本 0.1.4
- 添加
MongoDocumentSchemator
和MongoFieldSchemator
0.1.3 版
- 添加
TransactionHelper
项目详情
关
小丑-mongodb -0.1.4.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 60e897417a0fdcd791fb993d7e17f4b1370ddd517a00f00dfbb3e322300a8873 |
|
MD5 | 22747094adc12d147f5a435edba25f80 |
|
布莱克2-256 | 5ece8e836e3776ec3171274c33ac79a1e172e91a92d6274b6048f5cfcd03441f |