Refty/mongo-thingy

Database discovery isn't documented nor working correctly

Closed this issue · 8 comments

For instance:

If I have a database sport with a collection synchronised_swimming and I name the class

class SynchronisedSwimming(Thingy):
    collection_name = "synchronised_swimming"
    database_name = "sport"

I have to specify the database; if not it will use the synchronised database which does not make sense in that context.

How did you connect? The expected behavior is that Mongo-Thingy will only try to "guess" the database name (based on the class name construct) if it doesn't already have a database registered for that thingy.

The thing is: If I have a class SynchronisedSwimming I want to access the collection 'synchronised_swimming'. But because of the CamelCase the collection used is 'swimming' instead.
even if I say database_name = 'sport'

That's my point the 'guessing' part is not in the documentation.

Please answer my question. If you'd have been connected to a database in the first place, it shouldn't have tried to guess the database, and should have used "synchronised_swimming" as the collection name. If it did not, this is not just a documentation problem, but a bug.

Well, looks like it's not the case.

Here what happened:
I first tried

class SynchronisedSwimming(Thingy):
    pass

And it connected to the "synchronised" Database with the "swimming" collection

I then tried

class SynchronisedSwimming(Thingy):
    database_name = "sport"

And it connected to the "sport" Database with the "swimming" collection

I then tried

class SynchronisedSwimming(Thingy):
    collection_name = "synchronised_swimming"
    database_name = "sport"

And it connected to the "sport" Database with the "synchronised_swimming" collection


I thought that by specifying the database the collection name would not be implied but it is not the case.

I'm using mongo-thingy 0.7.0 by the way.

Maybe I should have selected the database properly during the connect part ?

The second example is definitely a bug.

For the first example, did you use connect with a default database (something like mongodb://domain/database)?

I think the answer is yes:

@ramnes I used something like

def init():
    config = app.config.get_namespace("MONGO_")
    connect(**config)

And I set the env like so:

env = MONGO_HOST=mongodb://localhost/sport

So the first example in your previous comment is a bug too. I guess there some work needed in Thingy too, so I've opened Refty/thingy#6.

Hey @guilbep,

Code is fixed and released; all your examples should work now!

The documentation part will come when we'll have a real one on RTFD.

Thanks for the bug report.