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

Database discovery isn't documented nor working correctly #6

Closed
guilbep opened this issue Aug 21, 2017 · 8 comments
Closed

Database discovery isn't documented nor working correctly #6

guilbep opened this issue Aug 21, 2017 · 8 comments
Assignees
Labels

Comments

@guilbep
Copy link

guilbep commented Aug 21, 2017

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.

@ramnes
Copy link
Member

ramnes commented Sep 19, 2017

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.

@guilbep
Copy link
Author

guilbep commented Sep 19, 2017

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.

@ramnes
Copy link
Member

ramnes commented Sep 19, 2017

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.

@ramnes ramnes changed the title Documentation: the way the database is defined (implicitly) is not documented Database discovery isn't documented (or working) correctly Sep 19, 2017
@ramnes ramnes self-assigned this Sep 19, 2017
@guilbep
Copy link
Author

guilbep commented Sep 19, 2017

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 ?

@ramnes
Copy link
Member

ramnes commented Sep 19, 2017

The second example is definitely a bug.

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

@ramnes ramnes changed the title Database discovery isn't documented (or working) correctly Database discovery isn't documented nor working correctly Sep 19, 2017
@ramnes ramnes added the bug label Sep 19, 2017
@guilbep
Copy link
Author

guilbep commented Sep 19, 2017

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

@ramnes
Copy link
Member

ramnes commented Sep 20, 2017

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.

@ramnes
Copy link
Member

ramnes commented Nov 2, 2017

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.

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

No branches or pull requests

2 participants