bjartek / computer-database-mongo

Computer-database example from play 2.0 distribution with mongo as persistence using salat
33 stars 8 forks source link

Cannot connect to mongodb - invalid db name #1

Closed ghost closed 12 years ago

ghost commented 12 years ago

Mongodb is running, the database "mydb" exists. application.conf contains: mongo.url="mongodb://localhost/mydb"

When running http://localhost:9000/ we get:

CommandFailure: command failed [command failed [count] { "assertion" : "invalid db name: mongodb://localhost/mydb/" , "assertionCode" : 13280 , "errmsg" : "db assertion failure" , "ok" : 0.0}

com.mongodb.CommandResult$CommandFailure

Probably a configuration/documentation error. What is wrong?

ghost commented 12 years ago

mongo.url="mongodb://127.0.0.1:27017/mydb" creates a connection.

Now the error is: IllegalArgumentException: 'ok' should never be null...

MongoDB says:

[conn6] assertion 13530 bad or malformed command request? ns:mongodb://127.0.0.1:27017/mydb.$cmd query:{ count: "companies", query: {} }

Should the database not be created automatically?

bjartek commented 12 years ago

Hello. Thanks for reporting. I think my documentation is a little bit unclear or the name of the config key is bad.

try using mongo.url="mydb"

Should I rename the key to be mongo.db_name perhaps?

ghost commented 12 years ago

After analyzing the source code, I switched the valued to mongo.url="computer-database"

what works perfectly.

ghost commented 12 years ago

Oh yes rename it. Good property names can save time. I supposed that "computer-database" was just a placeholder until reading the source code. Or create a more flexible version where mongo.url accept any mongo url (not only connections to 127.0.0.1)

By the way: mongo.url="mydb" works perfectly.

Thanks for this project and the prompt answer.

bjartek commented 12 years ago

Will fix a more flexible way to create the mongo collection with support for host/port and name. Suggested config keys are

mongo.host mongo.url mongo.dbName