MongoDB
 sql >> Teknologi Basis Data >  >> NoSQL >> MongoDB

Mapreduce di driver asli mongodb ruby

Saya menemukan alasannya dan kode baru saya adalah

# Map function which emits the two necessary fileds like key and value to perform our operations
    map = "function(){" +
    "emit(this.cust_id,this.amount);" +
    "}; "

    # Reduce function reduces the values as per logic and outputs with key and value
    reduce = "function(key,values){" +
    "return Array.sum(values);" +
    "}"

    # Check this link fore reference :- http://www.rubydoc.info/github/mongodb/mongo-ruby-driver/master/Mongo/Collection:map_reduce
    # a customizable set of options to perform map reduce functions
    opts =  {
    :query => 
    {
    "status" => "S"
    },
    # out specifies where we need to output the map reduce output.
    # if we specify simply a name in string like "order_totals" it creates a collection in that name 
    # and stores in that
    # if we need to store in a temp memory and needed as output we need to give {:inline => 1} ans
    # :raw => true
    # check link :- http://docs.mongodb.org/manual/reference/command/mapReduce/#mapreduce-out-cmd
    :out => {:inline => 1}, 
    :raw => true
    }           

    result = COLLECTION_MAPREDUCE.map_reduce(map,reduce,opts)
    result["results"].each do |obj|
    puts obj    
    puts "\n ------------"
    end

Dalam opts saya harus memberikan out dan raw.i got mondar-mandir linkdi sini

Kode ini berfungsi dengan baik. Terima kasih.




  1. Redis
  2.   
  3. MongoDB
  4.   
  5. Memcached
  6.   
  7. HBase
  8.   
  9. CouchDB
  1. Cara Mengonversi Tampilan MongoDB menjadi Koleksi

  2. Memperbarui array dengan push dan slice

  3. Bagaimana memulihkan database MongoDB yang jatuh?

  4. Otomatis memadatkan ruang yang dihapus di mongodb?

  5. MongoDb mencari array bersarang antara dateTimes menggunakan Robomongo