Uploaded image for project: 'CASBAH'
  1. CASBAH
  2. CASBAH-4

Map Reduce works from command line, fails w/ Casbah

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Works as Designed
    • Affects Version/s: 2.1.2
    • Fix Version/s: None
    • Component/s: None
    • Labels:
    • Environment:
    • # Replies:
      9
    • Last comment by Customer:
      true

      Description

      Apologies in advance if this is something obvious.

      Error:
      Mon Sep 26 18:59:27 [conn34] mr ns: jayed.tweets
      Mon Sep 26 18:59:27 [conn34] query jayed.system.js reslen:20 0ms
      Mon Sep 26 18:59:27 [conn34] JS Error: SyntaxError: missing : after property id nofile_b:0
      Mon Sep 26 18:59:27 [conn34] compile failed for: function (){ emit(

      { this.topic }, { count: 1 }); }
      Mon Sep 26 18:59:27 [conn34] User Assertion: 13598:couldn't compile code for: _map
      Mon Sep 26 18:59:27 [conn34] mr failed, removing collection :: caused by :: 13598 couldn't compile code for: _map
      Mon Sep 26 18:59:27 [conn34] run command jayed.$cmd { drop: "tmp.mr.tweets_24" }
      Mon Sep 26 18:59:27 [conn34] CMD: drop jayed.tmp.mr.tweets_24
      Mon Sep 26 18:59:27 [conn34] command jayed.$cmd command: { drop: "tmp.mr.tweets_24" } ntoreturn:1 reslen:62 0ms
      Mon Sep 26 18:59:27 [conn34] run command jayed.$cmd { drop: "tmp.mr.tweets_24_inc" }
      Mon Sep 26 18:59:27 [conn34] CMD: drop jayed.tmp.mr.tweets_24_inc
      Mon Sep 26 18:59:27 [conn34] command jayed.$cmd command: { drop: "tmp.mr.tweets_24_inc" } ntoreturn:1 reslen:62 0ms

      Sample code
      val coll = mongo("jayed")("tweets")
      val map = "function (){ emit({ this.topic }

      ,

      { count: 1 }

      ); }"
      val reduce = "function(key, values) { var count = 0; values.forEach(function(v)

      { count += v['count']; }); return {count: count}; }"
      val out = coll.mapReduce( map , reduce , "tweetresults" , Some(MongoDBObject( "verbose" -> true )) )
      val tweetresults = mongo("jayed")("tweetresults")
      tweetresults.ensureIndex( MongoDBObject("count" -> 1 ) , "topic_count_index", false )
      tweetresults.find().toString() //is an empty iterator

      Tried also with MapReduceInlineOutput.

      Given a schema/data like
      {"topic" : "A" , "comment" : "hello world" } , {"topic": null , "comment" : "hello again" } , {"topic" : "A" , "comment" : "hello world finally" }



      Following works from command line

      map = function (){
      emit({ this.topic }, { count: 1 });
      }

      reduce = function(key, values) { var count = 0; values.forEach(function(v) { count += v['count']; }

      ); return

      {count: count}

      ; };

      db.tweets.mapReduce( map, reduce,

      { out: "tweetresults" }

      ); //
      db.tweetresults.ensureIndex(

      {count : 1}

      );
      db.tweetresults.find().sort(

      {count : 1}

      );

      One result for "topic" above is null as a value FWIW.

      Don't know if this affects 2.1.2 and/or 2.2, but Casbah version 2.1.5

      For some further background:

      http://stackoverflow.com/questions/7302300/group-by-aggregate-map-reduce-functions-in-mongodb-using-scala-casbah-rogue

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since reply:
                5 years, 51 weeks, 3 days ago
                Date of 1st Reply: