PyMongo Adapter for CrateDB

About

Mongo DB Is Web Scale, CrateDB too. Because CrateDB covers a reasonable amount of features of MongoDB, this is an experiment to provide an emulation layer for the PyMongo driver, so Python client programs and libraries may work unmodified.

What’s Inside

An amalgamated PyMongo driver, using CrateDB as a backend instead of MongoDB. It can run 95% of the MongoDB “Getting Started” tutorial successfully.

While coverage of the complete MongoDB API, and more advanced query translations, are pretty thin yet, freedom and performance are paramount. There are no Atlas Service Limits or MongoDB Limits and Thresholds in place.

Warning

Please note this is pre-alpha software, and is only intended for demonstration purposes.
Here be dragons. You have been warned.

Synopsis

Invoke your PyMongo-based application like this, using PyMongoCrateDBAdapter to wrap the invocation of pymongo.MongoClient(...), pointing the client to a CrateDB database server instead.

import pymongo
from cratedb_toolkit.adapter.pymongo import PyMongoCrateDBAdapter

with PyMongoCrateDBAdapter(dburi="crate://crate@localhost:4200"):
    client = pymongo.MongoClient("localhost", 27017)
    collection = client.foo.bar

    inserted_id = collection.insert_one({"author": "Mike", "text": "My first blog post!"}).inserted_id
    print(inserted_id)

    document = collection.find_one({"author": "Mike"})
    print(document)

Usage

Install the emulation package.

pip install --upgrade 'cratedb-toolkit[pymongo]'

Start CrateDB.

docker run --rm -it --name=cratedb \
  --publish=4200:4200 --publish=5432:5432 \
  --env=CRATE_HEAP_SIZE=2g crate/crate:nightly \
  -Cdiscovery.type=single-node

Invoke a Python-based program connecting to MongoDB using the pymongo package, for example the Python example program, which is exercising a few basic operations.

API Coverage

The most basic primitives: Loading data and querying it back.

Examples

To inspect and explore the capabilities of the driver adapter, please use the basic Python example program, and relevant test cases of the adapter subsystem.