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 6567559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:21:06+00:00 2026-05-25T14:21:06+00:00

I’m pretty new to MongoDB and MapReduce. I need to do some MapReduce on

  • 0

I’m pretty new to MongoDB and MapReduce. I need to do some MapReduce on a collection in my DB. The MAP and REDUCE_MAX functions work, since I was able to accomplish my needs in the Mongo interactive shell (v.1.8.2). However, I get an error trying to perform the same thing using the Mongo Java Driver (v. 2.6.3)

My MAP and REDUCE_MAX functions look like this:

String MAP =
            "function(){" +
                    "if(this.type != \"checkin\"){return;}" +
                    "if(!this.venue && !this.venue.id){return;}" +
                    "emit({userId:this.userId, venueId:this.venue.id}, {count:1});" +
                    "};";


String REDUCE_MAX =
            "function(key, values){" +
                    "var res = {count:0};" +
                    "values.forEach(function(value){result.count += value.count;});" +
                    "return res;" +
                    "};";

This is the command I’m executing:

MapReduceOutput sum = collection
                .mapReduce(MAP, REDUCE_MAX, null, null);

This is the error I get:

com.mongodb.CommandResult$CommandFailure: command failed [command failed [mapreduce] { "assertion" : "wrong type for BSONElement (replace) 10 != 2" , "assertionCode" : 13111 , "errmsg" : "db assertion failure" , "ok" : 0.0}

I don’t know which BSONElement has the wrong type. And I’ve already googled the assertionCode: 13111. I’ve also checked in the MongoDB log, but did not find any clues there.

Does anyone have an idea, what I could be missing/doing wrong? If you guys need more details, just let me know please.

  • 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-05-25T14:21:07+00:00Added an answer on May 25, 2026 at 2:21 pm

    Today I stumbled upon my mistake and figured to share the solution here, just in case somebody encounters a similar problem.

    The invocation of the mapReduce method was causing the problem:

    MapReduceOutput sum = collection
                    .mapReduce(MAP, REDUCE_MAX, null, null);
    

    Have a look at the Javadoc for this method:

    /**
     * performs a map reduce operation
     * Runs the command in REPLACE output mode (saves to named collection)
     *
     * @param map
     *            map function in javascript code
     * @param outputTarget
     *            optional - leave null if want to use temp collection
     * @param reduce
     *            reduce function in javascript code
     * @param query
     *            to match
     * @return
     * @throws MongoException
     * @dochub mapreduce
     */
    

    It states that the command is executed using REPLACE as output mode and that if one wants a temporary collection, the outputTarget should be null.

    Unfortunately though, the constructorMapReduceCommand, which is used in the mapReduce method, only allows the outputTarget to be nullable if the OutputType is set to INLINE (according to the Javadoc of MapReduceCommand.getOutputTarget()).

    So all I had to do is to change the third parameter from null to some String, like so:

    MapReduceOutput sum = collection
                    .mapReduce(MAP, REDUCE_MAX, "tmp", null);
    

    This was like the only parameter I had not played around with while trying to figure out why it didn’t work. I hope somebody might find this helpful.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I need a function that will clean a strings' special characters. I do NOT
I have thousands of HTML files to process using Groovy/Java and I need to

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.