mongodb - Mongo mapReduce, multiple source collections, conditionally include values from existing key -


i have multiple collections , creating single information collection via mapreduce based on both of contents. in reduce method, how can apply conditional logic based on source collection or if existing key output collection.

when reducing collection information collection:

  • i want sum values subset of fields specific input collection , overwrite fields. not want values existing key in information collection included in sum.
  • if key exists in information collection, want overwrite fields, preserving values of other fields if key exists.

when merging collection b information collection:

  • i want conditionally overwrite subset of fields collection b
  • preserving values of other fields if key exists.

currently trying following:

  • i have map function each of source collections emits uniform value. emitted value has field "source" indicates collection from.
  • i have single reduce function. first thing create object structured uniform value.
  • i have finalize function sets source field 'final', indicating existing key.
  • the reduce function checks source value, , tries discern logic use. if collection sums, if b replaces, if final tries follow merge logic.
  • i run mapreduce using reduce option, update keys.

the problem

  • i realized finalize called multiple times. eliminates ability discern logic should applying in reduce.

  • how apply conditional logic based on source collection or if existing key in reduce method?

how apply conditional logic based on source collection or if existing key in reduce method?

to this, need data "information" collection included in data sent reduce(). this, output "reduce" action. see output collection action. after reducing data collection (or b), "reduce" action instruct mongo reduce intersection (by key) of data , records in output collection.

if map() generates keys exist in "information" collection, reduce run on new records (from or b) , existing records (from "information"). obviously, mean reduce function becomes more complex, @ least have data need apply conditional logic.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -