Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-4073

Throw error in Aggregate

    • Type: Icon: Task Task
    • Resolution: Done
    • 12_01_17
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      Lets say i have this code:

      map = %Q{
        function() {
          emit(this.name, { likes: this.likes });
        }
      }
      
      reduce = %Q{
        function(key, values) {
          var result = { likes: 0 };
          values.forEach(function(value) {
            if(value.likes < 0){
                #{Rails.logger.error "likes are negativ" }
            }
            result.likes += value.likes;
          });
          return result;
        }
      }
      
      Band.where(:likes.gt => 100).map_reduce(map, reduce).out(inline: true)
      

      As you can see I want to record an error if the value.likes are negativ:

      #

      {Rails.logger.error "likes are negativ" }

      But this Code is executed each time I run the aggregate and not when the likes are negativ.

      What can I do to throw an error in the aggregate statement?

      Thanks

      Stackoverflow: http://stackoverflow.com/questions/30376363/throw-error-in-mongoid

            Assignee:
            Unassigned Unassigned
            Reporter:
            emmanuelmillionaer emmanuelmillionaer
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: