blitzdb
blitzdb copied to clipboard
getting error when using MongoBackend
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?
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.