Skip to content

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

Description

@jackywu

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions