NoSQL ; MongoDB

182 views
Skip to first unread message

Miguel Dias

unread,
Jan 29, 2013, 11:00:09 AM1/29/13
to mojol...@googlegroups.com
Hi,

I'm trying to use mongodb with mojolicious in the right way ... Just followed http://search.cpan.org/~friedo/MongoDB-0.503.3/lib/MongoDB/Tutorial.pod and it went ok. 

Well, i can insert/fetch records but what i really want to do is similar to this ( i suppose that when you use a NoSql database you should(must?) do this way, am I wrong??) : http://search.cpan.org/dist/MongoDBI/lib/MongoDBI.pm . However the note "NOTE: This librrary is scheduled for a complete rewrite in the comming months."  made me thought if there is another module or way to do.

Does anyone have an experience with mojolicious and mongodb willing to share ?

Ben van Staveren

unread,
Jan 29, 2013, 11:03:28 AM1/29/13
to mojol...@googlegroups.com
I just use Mojolicious::Plugin::Mongodb (since I wrote it) and that gives me
my MongoDB access :)

On 01/29/2013 11:00 PM, Miguel Dias wrote:
> Hi,
>
> I'm trying to use mongodb with mojolicious in the right way ... Just
> followed
> http://search.cpan.org/~friedo/MongoDB-0.503.3/lib/MongoDB/Tutorial.pod
> <http://search.cpan.org/%7Efriedo/MongoDB-0.503.3/lib/MongoDB/Tutorial.pod>
> and it went ok.
>
> Well, i can insert/fetch records but what i really want to do is similar to
> this ( i suppose that when you use a NoSql database you should(must?) do
> this way, am I wrong??) :
> http://search.cpan.org/dist/MongoDBI/lib/MongoDBI.pm . However the note
> /"NOTE: This librrary is scheduled for a complete rewrite in the comming
> months."/ made me thought if there is another module or way to do.
>
> Does anyone have an experience with mojolicious and mongodb willing to share ?
> --
> You received this message because you are subscribed to the Google Groups
> "Mojolicious" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mojolicious...@googlegroups.com.
> To post to this group, send email to mojol...@googlegroups.com.
> Visit this group at http://groups.google.com/group/mojolicious?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

--
Ben van Staveren
phone: +62 81 70777529
email: benvans...@gmail.com

Miguel Dias

unread,
Jan 29, 2013, 11:23:11 AM1/29/13
to mojol...@googlegroups.com
I saw that plugin as well... 

I think I'm missing something ( don't take the following comments wrong): but from the description of your plugin you are using it to connect to mongodb, fetch collections, etc etc but what about if you want to define attributes of a "class" say "Post" shouldn't you have a MongoDB::Document  and there you define "IdPost , int, required"; "Message, varchar2 "; Something alike ... 

Ain't the point of  NoSQL to define the attributes of a class for example in perl rather than in DB? Where do you define the "schema" of you database using your plugin ?

Similar to:

 package CDDB::Album;

    use MongoDBI::Document;

    # collection name
    store 'albums';

    # required fields
    key 'title',    is_str,  is_req;
    key 'released', is_date, is_req;

    # optional fields
    key 'rating', is_int, default => 1;

Ben van Staveren

unread,
Jan 29, 2013, 11:38:28 AM1/29/13
to mojol...@googlegroups.com
Ah, that's not what my plugin is for; there are some ORM's that handle MongoDB
though but not many. Mongoose is one, but realistically since NoSQL is
schemaless storage, it's often easier to just work with the raw hash data you
get back than it is to have an ORM. In cases where people need it, I think
most just end up writing their own mapper classes to deal with it.

On 01/29/2013 11:23 PM, Miguel Dias wrote:
> I saw that plugin as well...
>
> I think *I'm missing something* ( don't take the following comments wrong):
> but from the description of your plugin you are using it to connect to
> mongodb, fetch collections, etc etc but what about if you want to define
> attributes of a "class" say "Post" shouldn't you have a MongoDB::Document
> and there you define "IdPost , int, required"; "Message, varchar2 ";
> Something alike ...
>
> Ain't the point of NoSQL to define the attributes of a class for example in
> perl rather than in DB? Where do you define the "schema" of you database
> using your plugin ?
>
> Similar to:
>
> package CDDB::Album;
>
> use MongoDBI::Document;
>
> # collection name
> store'albums';
>
> # required fields
> key'title', is_str, is_req;
> key'released', is_date, is_req;
>
> # optional fields
> key'rating', is_int, default=> 1;
>
>
>
>
>
> On Tuesday, January 29, 2013 4:00:09 PM UTC, Miguel Dias wrote:
>
> Hi,
>
> I'm trying to use mongodb with mojolicious in the right way ... Just
> followed
> http://search.cpan.org/~friedo/MongoDB-0.503.3/lib/MongoDB/Tutorial.pod
> <http://search.cpan.org/%7Efriedo/MongoDB-0.503.3/lib/MongoDB/Tutorial.pod>
> and it went ok.
>
> Well, i can insert/fetch records but what i really want to do is similar
> to this ( i suppose that when you use a NoSql database you should(must?)
> do this way, am I wrong??) :
> http://search.cpan.org/dist/MongoDBI/lib/MongoDBI.pm
> <http://search.cpan.org/dist/MongoDBI/lib/MongoDBI.pm> . However the
> note /"NOTE: This librrary is scheduled for a complete rewrite in the
> comming months."/ made me thought if there is another module or way to do.
>
> Does anyone have an experience with mojolicious and mongodb willing to
> share ?
>

Miguel Dias

unread,
Jan 29, 2013, 11:53:49 AM1/29/13
to mojol...@googlegroups.com
Ah! Touché! :)
That was what i was looking for, thank you.

"it's often easier to just work with the raw hash data you get back than it is to have an ORM. " 

Hmmm so, you remove the "M" in MVC :p ? </joking>  Do you have an example so i can check it out ? 

Thanks again, for the quick answers. :)

Ben van Staveren

unread,
Jan 29, 2013, 12:11:46 PM1/29/13
to mojol...@googlegroups.com
Not really any example, but if you use the Mongodb plugin, suppose you want to
increase a view count when a page is loaded, you'd just do this:

$self->model('yourdatabase.pageviewcollection')->update(
{
_id => $self->req->base->url
},
{
'$inc' => { 'views' => 1 },
},
{ upsert => 1 }
);

Or there's a collection that has an email address, name, and password in it,
you can do things like this:

if(my $user = $self->model('yourdatabase.users')->find_one({ email =>
$entered_email_address })) {
$self->app->log('user ' . $user->{name} . ' logged in')
}

And so on and so forth, basically it's exactly the same as the things
mentioned in MongoDB::Collection, it just allows for some easier access and
saves on typing :)





On 01/29/2013 11:53 PM, Miguel Dias wrote:
> Ah! Touch�! :)
> <http://search.cpan.org/%7Efriedo/MongoDB-0.503.3/lib/MongoDB/Tutorial.pod
> <http://search.cpan.org/%7Efriedo/MongoDB-0.503.3/lib/MongoDB/Tutorial.pod>>
>
> > and it went ok.
> >
> > Well, i can insert/fetch records but what i really want to do is
> similar
> > to this ( i suppose that when you use a NoSql database you
> should(must?)
> > do this way, am I wrong??) :
> > http://search.cpan.org/dist/MongoDBI/lib/MongoDBI.pm
> <http://search.cpan.org/dist/MongoDBI/lib/MongoDBI.pm>
> > <http://search.cpan.org/dist/MongoDBI/lib/MongoDBI.pm
> <http://search.cpan.org/dist/MongoDBI/lib/MongoDBI.pm>> . However the
> > note /"NOTE: This librrary is scheduled for a complete rewrite in the
> > comming months."/ made me thought if there is another module or
> way to do.
> >
> > Does anyone have an experience with mojolicious and mongodb
> willing to
> > share ?
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Mojolicious" group.
> > To unsubscribe from this group and stop receiving emails from it, send an
> > email to mojolicious...@googlegroups.com <javascript:>.
> > To post to this group, send email to mojol...@googlegroups.com
> <javascript:>.
> <http://groups.google.com/group/mojolicious?hl=en>.
> > For more options, visit https://groups.google.com/groups/opt_out
> <https://groups.google.com/groups/opt_out>.
> >
> >
>
> --
> Ben van Staveren
> phone: +62 81 70777529
> email: benvans...@gmail.com <javascript:>

Miguel Dias

unread,
Jan 29, 2013, 1:01:04 PM1/29/13
to mojol...@googlegroups.com
Finally, you should ask mongodb mantainers to add your plugin: http://www.mongodb.org/display/DOCS/Perl+Language+Center .


On Tuesday, January 29, 2013 5:11:46 PM UTC, Ben van Staveren wrote:
Not really any example, but if you use the Mongodb plugin, suppose you want to
increase a view count when a page is loaded, you'd just do this:

$self->model('yourdatabase.pageviewcollection')->update(
   {
     _id => $self->req->base->url
   },
   {
     '$inc' => { 'views' => 1 },
   },
   { upsert => 1 }
);

Or there's a collection that has an email address, name, and password in it,
you can do things like this:

if(my $user = $self->model('yourdatabase.users')->find_one({ email =>
$entered_email_address })) {
   $self->app->log('user ' . $user->{name} . ' logged in')
}

And so on and so forth, basically it's exactly the same as the things
mentioned in MongoDB::Collection, it just allows for some easier access and
saves on typing :)





On 01/29/2013 11:53 PM, Miguel Dias wrote:
> Ah! Touch�! :)

Scott

unread,
Feb 4, 2013, 3:24:27 PM2/4/13
to mojol...@googlegroups.com
> On Tuesday, January 29, 2013 10:03:28 AM UTC-6, Ben van Staveren wrote:
> I just use Mojolicious::Plugin::Mongodb (since I wrote it) and that gives me
> my MongoDB access :)

Just a note that MongoDB::Connection is now deprecated in favor of MongoDB::MongoClient. The deprecation could eventually effect your module.

The MongoDB module has undergone many changes in the last few months. I went to install on dotCloud a few months back and found that there was no longer any non-dev version available for a time. The last maintainer's archive is gone from CPAN (did not think that was possible).

The autoloading of db names and collection names is also deprecated and will cause numerous warnings. I assume the ORMs will need to be updated as well.

Just saw on Twitter that Sebastian is working on his driver again. I will look forward to checking that out.

- Scott

Ben van Staveren

unread,
Feb 4, 2013, 3:49:16 PM2/4/13
to mojol...@googlegroups.com
Yeah I've seen that, it's the only thing that'd affect the plugin really; the
rest of the code (at least, if you use the helpers provided by the plugin)
always use get_database and get_collection, mainly because that autoloading
trick has caused a few weird bugs (and still does to an extent, typing
coll->findOne instead of coll->find_one doesn't quite get you what you thought
you'd get) so I attempted to work around that.

I'm not entirely happy with the direction the new driver's going but at the
very least someone's working on it again, at 10gen it seemed to just get
neglected and sort of wasted away due to a lack of any better code.

Hope Sebastian can get his driver going :)

Sebastian Riedel

unread,
Feb 4, 2013, 4:07:14 PM2/4/13
to mojol...@googlegroups.com
> Hope Sebastian can get his driver going :)

First alpha release is almost ready, just working on tests and basic documentation now. ;)

--
Sebastian Riedel
http://twitter.com/kraih
http://mojolicio.us

Vincent HETRU

unread,
Feb 5, 2013, 5:30:34 AM2/5/13
to mojol...@googlegroups.com

I'm not entirely happy with the direction the new driver's going but at the
very least someone's working on it again, at 10gen it seemed to just get
neglected and sort of wasted away due to a lack of any better code.

Hope Sebastian can get his driver going :)
+1 most of other languages drivers for mongoDB got read preferences functionnality implemented already but not the Perl driver :(

sri

unread,
Feb 5, 2013, 10:13:50 AM2/5/13
to Mojolicious
> +1 most of other languages drivers for mongoDB got read preferences
> functionnality implemented already but not the Perl driver :(

That's the kinda feature that will be really hard for me to implement,
since i don't have permanent access to all the different MongoDB
setups for testing. I'm still hoping mongos will at some point become
a general purpose proxy, so driver authors don't have to worry about
this stuff anymore.

--
sebastian

sri

unread,
Feb 5, 2013, 11:43:55 AM2/5/13
to Mojolicious
> That's the kinda feature that will be really hard for me to implement,
> since i don't have permanent access to all the different MongoDB
> setups for testing. I'm still hoping mongos will at some point become
> a general purpose proxy, so driver authors don't have to worry about
> this stuff anymore.

To be more precise, for now i think i will limit the supported feature
set to things that can be tested with a free MongoHQ sandbox.

--
sebastian

Vincent HETRU

unread,
Feb 6, 2013, 4:12:02 AM2/6/13
to mojol...@googlegroups.com, kra...@googlemail.com
What do you mean by "all the different MongoDB setups"? Can we help with that?

Anyway we're impatient to discover your new driver.

But read preferences is just the feature we were waiting for when using replica set. That's why we're not happy with the official driver not getting it implemented. But for the rest apart from some thing that could be improved we're quite happy with this driver.

Thanks for your great works on Mojo. 

sri

unread,
Feb 6, 2013, 8:59:29 AM2/6/13
to Mojolicious
Just released the first alpha. :)

https://github.com/kraih/mango

--
sebastian

Joe Landman

unread,
Feb 6, 2013, 9:01:09 AM2/6/13
to mojol...@googlegroups.com
Thank you!

Sent from my iPad

sri

unread,
Feb 6, 2013, 11:02:04 AM2/6/13
to Mojolicious
> What do you mean by "all the different MongoDB setups"?

Replica sets, shards, sharded replica sets, sharded replica sets in
multiple datacenters, different failover scenarios. Basically
everything replication is really hard to unit test.

http://docs.mongodb.org/manual/applications/replication/

--
sebastian

sri

unread,
Feb 8, 2013, 7:39:08 PM2/8/13
to Mojolicious
> I'm still hoping mongos will at some point become
> a general purpose proxy, so driver authors don't have to worry about
> this stuff anymore.


Btw. this is the change i was referring to, vote for it if you can. ;)

https://jira.mongodb.org/browse/SERVER-1594

--
sebastian

Vincent HETRU

unread,
Feb 9, 2013, 10:03:06 AM2/9/13
to mojol...@googlegroups.com, kra...@googlemail.com
Good, You got my vote.
Reply all
Reply to author
Forward
0 new messages