SoftInstigate / restheart

Rapid API Development with MongoDB
https://restheart.org
GNU Affero General Public License v3.0
805 stars 171 forks source link

RH v1.1 - "db not found" error with mongodb 2.x #71

Closed singhvikram704 closed 8 years ago

singhvikram704 commented 8 years ago

Hi

I am using uri :- mongo-uri: mongodb://127.0.0.1/27017

Mongo is running on port 27017

Hitting url http://localhost:8080/test/products

But it always giving error message:- "message": "Db 'test' does not exist".

Could you please provide the solution for it.

Thanks

ujibang commented 8 years ago

you have to create the db test first

with httpie client

http --json PUT http://localhost:8080/test

If you enabled security on RESTHeart you can pass the username and password with the -a option

http --json -a a:a PUT http://localhost:8080/test
singhvikram704 commented 8 years ago

i have already created db at my local by mongo shell. but still not able to connect.

Similarly, i am using mongolab for database. If i put its uri in restheart.yml then it connected it but when i hit for db, again it show error that db XXXX does not exits.

ujibang commented 8 years ago

First your mongo-uri is wrong! Should be (note the colon : in place of the slash / before 27017).

mongo-uri: mongodb://127.0.0.1:27017

However I tried locally and this mistake should not prevent you to connect to your local mongodb (since 27017 is the default port).

1) How did you create the db using the mongodb shell? Note that in mongodb the db is actually created when some data is inserted in a collection so, for instance:

> use test
> db.coll.insert( {a:1} )

2) Have you tried to create the db as I suggested?

with PUT /test, RESTHeart actually creates the db.

3) which roles does the mongodb user have (I guess from your mongo-uri that you local mongodb is running without authentication enabled, but what about the mongolab)?

Note that you need it to have readWrite role on test to be able to create the db with RESTHeart?

singhvikram704 commented 8 years ago

I have already inserted lot of data in test db in user collection. but was not able to connect. I attached two clicks for it. 1 2

For mongolab(https://mongolab.com/) I created db->collection->document over there, Added uri in .yml, started restheart but same error giving as for local db.

ujibang commented 8 years ago

Which RESTHeart and MongoDB versions?

Please report output of following request:

GET 127.0.0.1:8989/

ujibang commented 8 years ago

FYI

I have created a test account on mongolab (mongodb version 3.0.7), tried it and it worked.

After db creation on mongolab, I had to create the db via RESTHeart first as mentioned before (PUT /db)

ujibang commented 8 years ago

I reproduced the issue using mongodb 2.6

Going to fix it asap.......

Can you confirm you are using mongodb 2.x?

SiddharthaBhatia commented 8 years ago

Hello ujibang,

I am also facing a similar issue. I am using restheart-1.1.0 and mongodb ver 2.6.11 from MongoLab.

I have given the following value to the mongo uri under restheart.yml: mongodb://:@ds027695-a0.mongolab.com:27695,ds027695-a1.mongolab.com:27695/pp?replicaSet=rs-ds027695

Output for http://localhost:8080/pp can be found below:

{ _links: { self: { href: "/pp" } }, http status code: 404, http status description: "Not Found", message: "Db 'pp' does not exist" }

Please note that the database with the name exists on mongolab. I also tried creating db with the name < pp > via RESTHeart by using (PUT /db). However, that did not help. I also cannot create a new db directly with the (PUT /db) as I get the following error:

{ "_links": { "self": { "href": "/pp2" } }, "http status code": 403, "http status description": "Forbidden", "message": "The MongoDB user does not have enough permissions to execute this operation." }

Your response awaited to proceed further.

Thank you, Siddhartha Bhatia

singhvikram704 commented 8 years ago

I agree, its working fine with 3.0.7 as provide by mongolab.

But not working with 2.x

Thanx ujibang for you continue support.

Regards Vikram Singh

ujibang commented 8 years ago

I fixed it in branch 1.1.x, all my tests succeed for version 2.6 as well

can you double check it (you need git, jdk1.8 and maven)?

to build it:

$ git clone https://github.com/SoftInstigate/restheart.git
Cloning into 'restheart'...
remote: Counting objects: 11141, done.
remote: Compressing objects: 100% (130/130), done.
remote: Total 11141 (delta 59), reused 0 (delta 0), pack-reused 10985
Receiving objects: 100% (11141/11141), 2.40 MiB | 520.00 KiB/s, done.
Resolving deltas: 100% (6528/6528), done.
Checking connectivity... done.

$ cd restheart
$ (master) git checkout 1.1.x
Branch 1.1.x set up to track remote branch 1.1.x from origin.
Switched to a new branch '1.1.x'

$ (1.1.x) mvn package
...

$ java -jar target/restheart.jar <conf-file-path-relative-to-jar-file>

if you confirm it is working in you use case, I'll release 1.1.1 asap

singhvikram704 commented 8 years ago

Hi ujibang

As per you instruction i configured api in eclipse and tested again but this time its giving error with 2.6 & 3.0.7:

com.mongodb.CommandFailureException: { "serverUsed" : "ds056815.mongolab.com:56815" , "ok" : 0.0 , "errmsg" : "not authorized on admin to execute command { fsync: 1 }" , "code" : 13} .

This message was coming with restheart versions <1.x

ujibang commented 8 years ago

@singhvikram704 please pull and try again

I fixed it; however that log message is just about restheart not able to fsync data at shutdown.

I actually removed this step since it is not necessary (mongodb does it automatically at intervals) and requires a special permission on admin db (that you mongolab user does not have)

ujibang commented 8 years ago

fixed in release 1.1.1

singhvikram704 commented 8 years ago

Working fine with latest release