Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to set the storage engine to 'flat-file' in BSON format ? #95

Open
jackywu opened this issue May 20, 2024 · 1 comment
Open

how to set the storage engine to 'flat-file' in BSON format ? #95

jackywu opened this issue May 20, 2024 · 1 comment

Comments

@jackywu
Copy link

jackywu commented May 20, 2024

I guys, I can't find a relevant info for that from docs.
how to set the storage engine to 'flat-file' in BSON format ?

and this one raise exception.

from montydb import set_storage, MontyClient


set_storage("default.db", use_bson=True)  # optional step
client = MontyClient("default.db")  # use current working dir if no path given

# >>> from montydb import MontyClient
col = client.db.test
col.insert_many([{"stock": "A", "qty": 6}, {"stock": "A", "qty": 2}])
cur = col.find({"stock": "A", "qty": {"$gt": 4}})
print(list(cur))
➜  montydb-demo .venv/bin/python main.py
Traceback (most recent call last):
  File "/Users/jackywu/Repository/demo/montydb-demo/main.py", line 5, in <module>
    client = MontyClient("default.db")  # use current working dir if no path given
             ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jackywu/Repository/demo/montydb-demo/.venv/lib/python3.12/site-packages/montydb/client.py", line 41, in __init__
    storage_cls = provide_storage(repository)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jackywu/Repository/demo/montydb-demo/.venv/lib/python3.12/site-packages/montydb/configure.py", line 269, in provide_storage
    _bson_init(_session["use_bson"])
  File "/Users/jackywu/Repository/demo/montydb-demo/.venv/lib/python3.12/site-packages/montydb/configure.py", line 279, in _bson_init
    bson.init(use_bson)
  File "/Users/jackywu/Repository/demo/montydb-demo/.venv/lib/python3.12/site-packages/montydb/types/bson.py", line 67, in init
    from ._bson import BSON_
  File "/Users/jackywu/Repository/demo/montydb-demo/.venv/lib/python3.12/site-packages/montydb/types/_bson.py", line 5, in <module>
    class BSON_(types.ModuleType):
  File "/Users/jackywu/Repository/demo/montydb-demo/.venv/lib/python3.12/site-packages/montydb/types/_bson.py", line 7, in BSON_
    from bson import (
ImportError: cannot import name 'SON' from 'bson' (/Users/jackywu/Repository/demo/montydb-demo/.venv/lib/python3.12/site-packages/bson/__init__.py)

``

besides, can I set a user and password to protect the connection to the local falt-file db file?
@davidlatwe
Copy link
Owner

Hi @jackywu , do you have pymongo installed for accessing their bson module?

Although, by looking at your ImportError, you do have bson package in your venv. Which is strange to me that SON class was not able to import.

I just tested the code snippet you provided with a clean Python 3.12 venv and I got no error.


besides, can I set a user and password to protect the connection to the local falt-file db file?

Unfortunately, no. There are no actual server running in between your data to provide such protection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants