adewes / blitzdb

Blitz is a document-oriented database for Python that is backend-agnostic. It comes with a flat-file database for JSON documents and provides MongoDB-like querying capabilities.
http://blitzdb.readthedocs.org
MIT License
331 stars 37 forks source link

getting error when using MongoBackend #67

Open ShawnXu opened 8 years ago

ShawnXu commented 8 years ago

I was glad to find out that blitzdb offers a MongoDB wrapper so I tried it out. Unfortunately I couldn't get it to work

>>> backend = blitzdb.MongoBackend('mongo://127.0.0.1:27017/', True)
>>> doc = blitzdb.Document({'name': 'Shawn'})
>>> doc.save(backend)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\Users\shawn\AppData\Local\Programs\Python\Python35-32\lib\site-packages\blitzdb-0.2.12-py3.5.egg\blitzdb\document.py", line 449, in save
    return backend.save(self)
  File "c:\Users\shawn\AppData\Local\Programs\Python\Python35-32\lib\site-packages\blitzdb-0.2.12-py3.5.egg\blitzdb\backends\mongo\backend.py", line 151, in save
    return self.save_multiple([obj])
  File "c:\Users\shawn\AppData\Local\Programs\Python\Python35-32\lib\site-packages\blitzdb-0.2.12-py3.5.egg\blitzdb\backends\mongo\backend.py", line 144, in save_multiple
    self.db[collection].save(attributes)
TypeError: string indices must be integers

I'm sure my mongodb server is running fine. I suppose the usage against the MongoDB backend should be the same. There isn't much documentation on read docs. Am I doing something wrong?

bieli commented 7 years ago

I suggesting look at this example: https://github.com/adewes/blitzdb/blob/master/blitzdb/backends/mongo/backend.py#L51

First You need connection from pymongo and second from MongoDB you get database object expected by first argument in blitzdb.MongoBackend() method.