Click or drag to resize

ViewSetMapReduce Method

Defines the View's MapDelegate and ReduceDelegate.

Namespace:  Couchbase.Lite
Assembly:  Couchbase.Lite (in Couchbase.Lite.dll) Version: 1.4.1-b107
Syntax
C#
public bool SetMapReduce(
	MapDelegate map,
	ReduceDelegate reduce,
	string version
)

Parameters

map
Type: Couchbase.LiteMapDelegate
The MapDelegate to set.
reduce
Type: Couchbase.LiteReduceDelegate
The ReduceDelegate to set.
version
Type: SystemString
The key of the property value to return. The value of this parameter must change when the MapDelegate and/or ReduceDelegate are changed in a way that will cause them to produce different results.

Return Value

Type: Boolean
true if the MapDelegate and ReduceDelegate were set, otherwise false. If the values provided are identical to the values that are already set, then the values will not be updated and false will be returned. In addition, if true is returned, the index was deleted and will be rebuilt on the next Query execution.
Remarks
Defines a view's functions. The view's definition is given as a class that conforms to the Mapper or Reducer interface (or null to delete the view). The body of the block should call the 'emit' object (passed in as a paramter) for every key/value pair it wants to write to the view. Since the function itself is obviously not stored in the database (only a unique string idenfitying it), you must re-define the view on every launch of the app! If the database needs to rebuild the view but the function hasn't been defined yet, it will fail and the view will be empty, causing weird problems later on. It is very important that this block be a law-abiding map function! As in other languages, it must be a "pure" function, with no side effects, that always emits the same values given the same input document. That means that it should not access or change any external state; be careful, since callbacks make that so easy that you might do it inadvertently! The callback may be called on any thread, or on multiple threads simultaneously. This won't be a problem if the code is "pure" as described above, since it will as a consequence also be thread-safe.
See Also