Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8704871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:13:16+00:00 2026-06-13T03:13:16+00:00

am I correct in that MongoDB map/reduce feature is not available on Mongoid Criteria

  • 0

am I correct in that MongoDB map/reduce feature is not available on Mongoid Criteria for MongoId version 2+

Can any one confirm this I have a criteria

Here my Query

class PerformerSource
  scope :active_performers,where(:active => true).only([:performer_id, :sort_order,:stage_name, :photo, :large_photo, :status, :current_performance_type,:current_sign_in_at])
end

PerformerSource.active_performers.order_by([:sort_order,:desc])

I want to apply map/reduce function to it

something like this

PerformerSource.active_performers.order_by([:sort_order,:desc]).map_reduce(PerformerSource.map,PerformerSource.reduce)

but whenever I do this it return with error

NoMethodError: undefined method `map_reduce’ for #

Checking if the map/reduce is available at all

PerformerSource.active_performers.order_by([:sort_order,:desc]).respond_to?(:map_reduce)
=> false

PerformerSource.respond_to?(:map_reduce)
=> false

So am I correct in my believe since I see Mongoid-3 has a provision of adding map/reduce in Mongoid-criteria over here but cant find the same in mongoid 2

I can upgrade mongoid (I wish I could) since the application is running on Ruby-1.8.7 and mongoid 3 required ruby-1.9+

So can let me if the map/reduce wont work on criteria how to run the map/reduce then taking the other conditions in account i.e
active_performers.order_by([:sort_order,:desc])

Note: I just for clarity in haven’t added the map and reduce function

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T03:13:17+00:00Added an answer on June 13, 2026 at 3:13 am

    I have produced the following monkey patch, which I’m using in production:

    
    module Mongoid
    
      module Criterion #:nodoc:
        module MapReduce
          def map_reduce(map, reduce, options = {})
            opts = {:out => {:inline => 1}, :raw => true, :query => selector}.merge(options)
            klass.collection.map_reduce(map, reduce, opts)
          end
          alias :mapreduce :map_reduce
        end
      end
    
    end
    
    

    This way I can execute map-reduce on a criteria. And if you want to execute it on all, then either use .all or .scoped (which I prefer), like PerformerSource.scoped.map_reduce(..)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the correct syntax in MongoDB to return all queries that meet the
I am wondering whether map reduce job in mongodb has anything to do with
Am I correct that the only way to prevent a method from being executed
Is it correct that the reveal applescript command is broken with iTunes 9? Works:
I'm new to Symfony. Is my understanding correct that the User class is actually
(1). When using C++ template, is it correct that the compiler (e.g. g++) will
My Visual Studio 2008 debugger is showing integers as hexadecimals, how to correct that?
Is that correct: When I query a value before validation (or if validation failed)
Well, I know that correct escaping will help to prevent SQL injection. But I
Like in: u'Hello' My guess is that it indicates "Unicode", is that correct? If

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.