Skip to main content

Add additional feature for mongomock.

Project description!--None.svg?style=social

Welcome to mongomock_mate Documentation

Use mongomock_mate:

Just import mongomock_mate at begin of your script. It use monkey patch:

import mongomock_mate


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"}])


# load
db = client["test"]

# other params
def dump_db(self, file,
    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:


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.

Github Issue.

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"))


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

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 hashes)

Uploaded source

Built Distribution

mongomock_mate-0.0.1-py2-none-any.whl (24.9 kB view hashes)

Uploaded py2

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page