LibreCat / Catmandu-Store-MongoDB

A searchable store backed by MongoDB
https://metacpan.org/pod/Catmandu::Store::MongoDB
4 stars 2 forks source link

Additions to Catmandu::Store::MongoDB #1

Closed petrakohorst closed 12 years ago

petrakohorst commented 12 years ago

I added three methods to Catmandu::Store::MongoDB: getAll -> get all records in DB, getByFieldValue -> gets records with specified Value in specified Field, selectField -> returns all records but reduced to specified Field and _id

Please review.

nics commented 12 years ago

hi petra,

i see several probems with this:

that being said i want to add something like getByFieldValue (aka indexes)

now these methods are handy to have but it's probably better to make a subclass of Store::MongoDB or put them in a Moo::Role until then?

regards, nicolas

petrakohorst commented 12 years ago

Hi Nicolas,

thanks for the quick answer. I see what you mean about the common interface... I'll put those methods into a subclass of Store::MongoDB then (or find a way to work around them altogether), since I am not really familiar with Moo yet. Renaming the subs so they'll match the Catmandu naming convention should be no problem.

But, can the getAll method (renamed to to_array) stay in Store::MongoDB::Bag? Or should I put that into my new subclass as well?

Regards, Petra

nics commented 12 years ago

hi petra,

yes to_array can stay, i'll merge it in but it should return a reference to the array, that's what to_array usually returns:

sub to_array {                                                                                                            
    my ($self) = @_;                                                                                                      
    my @all = $self->collection->find->all;                                                                               
    \@all;                                                                                                                
}  

i'm working on prividing efficient versions of these Iterable methods in Store::Mongo:

pluck($key)->to_array can be used instead of selectField($key) in your case select($key => $val)->to_array can be used instead of getByFieldValue($key, $val)

these probably do what you need for Catmandu:Projects? ... then you won't need the subclass anymore and it''ll give you an idea on how to extend these methods to provide more efficient versions for a certain store

nicolas