Please try new Mongodb REST server written in java using Jetty

460 views
Skip to first unread message

Andyg

unread,
Apr 13, 2012, 8:08:08 PM4/13/12
to mongodb-user

I wrote a simple REST server based on Jetty
It's basically embedded Jetty with servlets

Some available features
can enble ssl
can enable ip filter
mongodb access (read,write,admin) based on user role

Source, need ant and JDK 1.5 or later
http://commondatastorage.googleapis.com/andreidata/mongoser-src.tar.gz

Binary, need JRE 1.6 or later
http://commondatastorage.googleapis.com/andreidata/mongoser.tar.gz

Please try and let me know
Thanks


Some examples with curl
mongoser="http://yourmongohost.com:8081"

list databases
curl -i "$mongohost/database"

drop database
curl -i "$mongohost/database?dbname=foo" -XDELETE

get db stat
curl -i "$mongohost/database?dbname=foo&op=stats"

list collections
curl -i "$mongohost/collection?dbname=foo"

get col stat
curl -i "$mongohost/collection?dbname=foo&op=stats&colname=test"

create col
curl -i "$mongohost/collection?dbname=foo&colname=test" -XPUT


add record
curl -i "$mongohost/write?dbname=foo&colname=test" -XPUT --data-binary
'{name:"foo"}'

add multi record must be separated by newline
curl -i "$mongohost/write?dbname=foo&colname=test" -XPUT --data-binary
$'{name:"foo"}\n{name:"moo"}\n{name:"cow"}'

update record, first field is condition, must be separated by newline
curl -i "$mongohost/write?dbname=foo&colname=test" -XPOST --data-
binary $'{name:"foo"}\n{name:"newfoo"}'

delete records with condition
curl -i "$mongohost/write?dbname=foo&colname=test" -XDELETE -d
'{name:"newfoo"}'

read all records in collection
curl -i "$mongohost/query?dbname=foo&colname=test"

with limit
curl -i "$mongohost/query?dbname=foo&colname=test&limit=3"
with limit and skip
curl -i "$mongohost/query?dbname=foo&colname=test&limit=3&skip=3"
with condition
curl -i "$mongohost/query?dbname=foo&colname=test" -XPOST -
d'{name:"newfoo"}'

list indexes
curl -i "$mongohost/index?dbname=foo&colname=test"

add index
curl -i "$mongohost/index?dbname=foo&colname=test" -XPUT -d"{name:
1,age:1}"

delete index
curl -i "$mongohost/index?dbname=foo&colname=test" -XDELETE -d"{name:
1,age:1}"

Andyg

unread,
Apr 25, 2012, 12:04:18 AM4/25/12
to mongodb-user

I updated the server so queries can be cached with memcached
Here's page
https://sites.google.com/site/mongodbjavarestserver/home

On Apr 13, 8:08 pm, Andyg <gml...@gmail.com> wrote:
> I wrote a simpleRESTserver based  on Jetty
> It's basically embedded Jetty with servlets
>
> Some available features
> can enble ssl
> can enable ip filter
> mongodb access (read,write,admin) based on user role
>
> Source, need ant and JDK 1.5 or laterhttp://commondatastorage.googleapis.com/andreidata/mongoser-src.tar.gz
>
> Binary, need JRE 1.6 or laterhttp://commondatastorage.googleapis.com/andreidata/mongoser.tar.gz

Andyg

unread,
Apr 28, 2012, 11:36:42 PM4/28/12
to mongodb-user
I am writing this REST server firstly for my small project
There are about 910,000 entries that need to go to Mongodb
So I tried my rest server and inserted all 910000 fields doing
10,000 per http request from perl script
My mongodb rest server running on (http://hpcloud.com/pricing)
Standard Extra Small instance (which is free at the moment)
It averaged about 1000 inserts per second
I watched on server side using top command and java+mongo
two together did not take more than 50% of cpu during inserts
Not sure if it's good(fast) or not

https://sites.google.com/site/mongodbjavarestserver/home

On Apr 24, 11:04 pm, Andyg <gml...@gmail.com> wrote:
> I updated the server so queries can be cached with memcached
> Here's pagehttps://sites.google.com/site/mongodbjavarestserver/home

Andyg

unread,
May 6, 2012, 4:24:44 PM5/6/12
to mongodb-user
For whoever is interested to try
I added Lucene text search to my server
https://sites.google.com/site/mongodbjavarestserver/home

On Apr 28, 10:36 pm, Andyg <gml...@gmail.com> wrote:
> I am writing thisRESTserverfirstly for my small project
> There are about 910,000 entries that need to go to Mongodb
> So I tried myrestserverand inserted all 910000 fields doing
> 10,000 per http request from perl script
> My mongodbrestserverrunning on (http://hpcloud.com/pricing)
> Standard Extra Small instance (which is free at the moment)
> It averaged about 1000 inserts per second
> I watched onserverside using top command and java+mongo
> two together did not take more than 50% of cpu during inserts
> Not sure if it's good(fast) or not
>
> https://sites.google.com/site/mongodbjavarestserver/home
>
> On Apr 24, 11:04 pm, Andyg <gml...@gmail.com> wrote:
>
>
>
>
>
>
>
> > I updated theserverso queries can be cached with memcached

Andrei

unread,
Aug 30, 2012, 5:18:42 PM8/30/12
to mongod...@googlegroups.com
Do POST instead of GET request
See examples
curl -i "http://localhost:8081/query/my/users" -XPOST -d'{firstName:"joe"}'

On Thu, Aug 30, 2012 at 4:04 PM, Joseph Greenawalt
<joe.gre...@gmail.com> wrote:
> Hi,
> I'm trying to do a simple query:
> http://localhost:8081/query/my/users/?firstName=joe
> however that returns every record not the ones with firstName=joe
>
> Do you see what I'm doing wrong?
>
> Thanks,
> Joe
> --
> You received this message because you are subscribed to the Google
> Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com
> To unsubscribe from this group, send email to
> mongodb-user...@googlegroups.com
> See also the IRC channel -- freenode.net#mongodb

Joseph Greenawalt

unread,
Aug 31, 2012, 7:52:07 AM8/31/12
to mongod...@googlegroups.com
I agree.

On Friday, August 31, 2012 12:25:24 AM UTC-4, Michael Rose wrote:
> GET may make more sense for that operation given its lack of server-side mutation of data.
>
> On Thursday, August 30, 2012 3:18:52 PM UTC-6, Andyg wrote:Do POST instead of GET request

Octavian Covalschi

unread,
Aug 31, 2012, 12:36:19 PM8/31/12
to mongod...@googlegroups.com
I recently worked on a similar project, a homebrew rest server that's in front of mongodb, though instead of jetty I'm using netty :)

I must admit before that I knew much less about REST and it's philosophy...... I mean GET vs POST vs PUT vs DELETE and when/how to use them...

That said, my solution was to pass query params through URL params, instead of POST..

so in my case would've been this way

http://localhost:8081/query/my/users?where={firstName:"joe"}

of course you may need to url encode that, but it makes more sense than regular POST, even though I don't really like it...

Another option is still using GET but instead of parameters send as a body content, same as you're doing with post, just call get. RFC doesn't explicitly forbids that, so I don't see much harm... good to have choices I guess.

altruist

unread,
Jun 16, 2013, 8:23:51 PM6/16/13
to mongod...@googlegroups.com
Hello,

I have used your server and I have to admit that it is a great application.

I am trying to retrieve a few fields base on the _id filed and I am using the following format , but I get all the records back , can you please let me know if my syntax is correct.

http://localhost:8082/query?dbname=mydb&colname=mycollection&fields=myfield -XPOST -d'{_id:"51be48146a57f03f58b4d5f3"}'

I want only "myfield" to be returned for the matching _id , but it returns all the fields for all the ids , can you please let me know what I am doing wrong ?

Thanks.


On Friday, April 13, 2012 8:08:08 PM UTC-4, Andyg wrote:
Message has been deleted

altruist

unread,
Jun 17, 2013, 2:23:55 PM6/17/13
to mongod...@googlegroups.com
Re posting again because my intial post did not get posted .



Hello,

I have used your server and I have to admit that it is a great application.

I am trying to retrieve a few fields base on the _id filed and I am using the following format , but I get all the records back , can you please let me know if my syntax is correct.

http://localhost:8082/query?dbname=mydb&colname=mycollection&fields=myfield -XPOST -d'{_id:"
51be48146a57f03f58b4d5f3"}'

I want only "myfield" to be returned for the matching _id , but it returns all the fields for all the ids , can you please let me know what I am doing wrong ?

Thanks.


On Friday, April 13, 2012 8:08:08 PM UTC-4, Andyg wrote:
Reply all
Reply to author
Forward
0 new messages