mongoengine icon indicating copy to clipboard operation
mongoengine copied to clipboard

Make Document.get_collection public

Open warvariuc opened this issue 10 years ago • 3 comments

Document._get_collection is a protected method, but it's very useful for public usage. I don't see any reason why it should be protected. I guess this would suffice:

class Document(BaseDocument):
    ...
    get_collection = _get_collection

warvariuc avatar Dec 08 '15 07:12 warvariuc

That's a good point. I use Document._get_collection quite a lot myself whenever I need access to raw PyMongo Collection methods.

wojcikstefan avatar Dec 28 '16 05:12 wojcikstefan

How are you going to name it? Will it be a property collection?

mindojo-victor avatar Jan 27 '17 22:01 mindojo-victor

collection property sounds like the best choice, though I haven't fully considered all the implications.

No matter what public property we choose, we should make sure that users can't use it as a field name, e.g. this should raise an error immediately upon definition:

class DbDoc(Document):
    collection = StringField()

wojcikstefan avatar Feb 15 '17 13:02 wojcikstefan