#634 invalid
Thai Doan

CouchDB: Model#count results in undefined method.

Reported by Thai Doan | November 3rd, 2008 @ 01:25 AM

DataMapper::Adapters::CouchDBAdapter does not have an aggregate method.

User.count  #  NoMethodError: undefined method `aggregate' for #<DataMapper::Adapters::CouchDBAdapter>

Comments and changes to this ticket

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) November 3rd, 2008 @ 03:29 AM

    • State changed from “new” to “invalid”

    This is expected behavior for CouchDB and any non-RDBMS adapter. The Model#count method is not part of core DataMapper API.

    It appears from the error that you're requiring dm-aggregates somewhere. Removing the require statement will still result NotImplemented exception being thrown by the Model instead of the adapter. Is this the reason you were submitting this ticket? So it would throw NotImplemented, or for some other reason?

    I'm not entirely sure if CouchDB even supports any aggregate operations natively. I always thought the only way to sum/count/etc would be to iterate over all the records and do it in the ruby layer. It might be possible to update dm-aggregates to perform this under the hood for non-supported adapters, but it would probably be painfully slow.

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) November 3rd, 2008 @ 03:32 AM

    • State changed from “invalid” to “open”

    Whoops. Accidentally marked as invalid, fixing.

  • Thai Doan

    Thai Doan November 3rd, 2008 @ 03:55 AM

    Since CouchDB's reduce functions aggregate a list to a scalar value, there must be a possible solution to maintaining aggregation methods.

    I suppose the ticket is premature, as the view generator for this particular adapter is still being developed. Would the semantics of CouchDB still remain intact for using reduce functions?

  • geemus (Wesley Beary)

    geemus (Wesley Beary) November 30th, 2008 @ 12:04 PM

    • Assigned user changed from “Sam Smoot” to “geemus (Wesley Beary)”
    • State changed from “open” to “invalid”

    Although you can not use the aggregate functions from dm-aggregates, the current implementation should allow you to do any kind of aggregation you could want with views (which allow the use of all of couchdb's map/reduce goodness).

    Simply define a view with a reduce function and call it to get an OpenStruct object containing the results.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »