Add additional feature for mongomock.
Project description
Welcome to mongomock_mate Documentation
Use mongomock_mate:
Just import mongomock_mate at begin of your script. It use monkey patch:
import mongomock_mate
Features:
Data Persistence: dump and load data
import mongomock_mate
# dump
db = client["test"]
c_user = db["user"]
c_user.insert([{"_id": 1, "name": "Alice"}, {"_id": 2, "name": "Bob"}])
db.dump_db("test.json")
# load
db = client["test"]
db.load_db("test.json")
# other params
def dump_db(self, file,
pretty=False,
overwrite=False,
verbose=True):
"""
Dump :class:`mongomock.database.Database` to a local file. Only support
``*.json`` or ``*.gz`` (compressed json file)
:param file: file path.
:param pretty: bool, toggle on jsonize into pretty format.
:param overwrite: bool, allow overwrite to existing file.
:param verbose: bool, toggle on log.
"""
def load_db(self, file, check_dbname=True, verbose=True):
"""
Load :class:`mongomock.database.Database` from a local file.
:param file: file path.
:param check_dbname: bool, if True, the dbname has to be matched.
:param verbose: bool, toggle on log.
"""
Working with mongoengine ORM:
2018-07-30:
At mongomock==3.10.0, insert operation doesn’t work with latest mongoengine==0.15.3, because the implementation of WriteConcern is not correct in mongomock.
import mongomock_mate
from mongoengine import connect, Document, fields
connect('mongoenginetest', host='mongomock://localhost')
class User(Document):
_id = fields.IntField(primary_key=True)
name = fields.StringField()
User.objects.insert(User(_id=1, name="Alice"))
Quick Links
Install
mongomock_mate is released on PyPI, so all you need is:
$ pip install mongomock_mate
To upgrade to latest version:
$ pip install --upgrade mongomock_mate
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
mongomock_mate-0.0.1.tar.gz
(14.8 kB
view details)
Built Distribution
File details
Details for the file mongomock_mate-0.0.1.tar.gz
.
File metadata
- Download URL: mongomock_mate-0.0.1.tar.gz
- Upload date:
- Size: 14.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/2.7.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b55f54f2fa131290ac4251d05306a2599c6829d23682706ed93aba4d9597b0a |
|
MD5 | e2dc5839a5d7448bbf1632cc158ec6fc |
|
BLAKE2b-256 | 2ffbcd39929a176990af81f5d433c4b8fc403127903ce019370712ef100f47b1 |
File details
Details for the file mongomock_mate-0.0.1-py2-none-any.whl
.
File metadata
- Download URL: mongomock_mate-0.0.1-py2-none-any.whl
- Upload date:
- Size: 24.9 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/2.7.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 445fc674381a5435966a3fb0fbeb6463f189ee171af384f99ff76b505e956038 |
|
MD5 | b7a0f26ccf0fb112c40abf5be8022805 |
|
BLAKE2b-256 | 66552377f516c3d9365c6e66a19bfbf88a9b6a34f4ea06b092d11d7e3814684c |