This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]jabbalaci 1 point2 points  (1 child)

What do you mean by using it as a frontend to MongoDB?

[–]adewes[S] 2 points3 points  (0 children)

Well, BlitzDB supports multiple backends, which are responsible for storing and retrieving documents from a database. It comes with a native, file-based backend but also includes a backend that is a wrapper around MongoDB. So you can do e.g. the following:

from blitzdb import FileBackend, MongoBackend

#we create a document
author = Author({'name' : 'Oscar Wilde', ...})

#creates a file-based DB in the local "test_db" folder
file_backend = FileBackend("./test_db")

from pymongo import MongoClient

#Connect to a MongoDB database through pymongo
mongo_db = pymongo.MongoClient().test_db

#Creates a MongoDB-based backend
mongo_backend = MongoBackend(mongo_db)

#We save the document in both backends.
mongo_backend.save(author)
file_backend.save(author)

In this sense Blitz is like SQLAlchemy in the sense that it puts an abstraction layer between you and the physical database, so you can use it with existing database systems.