Hi,
I am converting a CBLite 1.4 app to version 2.7. This involves converting the Map/Reduce views into indexes and queries. One of the MapDelegate functions creates multiple indexes based on an array within a document. Could someone explain how to do this in CBLite 2.7, using the C# SDK?
public override MapDelegate Map
{
get
{
return (document, emit) =>
{
dynamic documentType;
document.TryGetValue("documentType", out documentType);
switch (documentType as string)
{
case "look":
{
dynamic items;
document.TryGetValue("items", out items);
if (items is JArray)
{
foreach (var item in items)
{
string divisionCode = item.divisionCode;
string styleSeasonCode = item.styleSeasonCode;
int id = item.id;
emit(string.Format("{0}_{1}_{2}",
divisionCode,
styleSeasonCode,
id
), item);
}
}
break;
}
default:
break;
}
};
}
}
As part of the upgrade to 2.7, I added a method called GetIndex, but it does not have a reference to a document.
It seems like each time a “look” document is saved, I need to create a new Index based on the items array of that document. Is this possible/practical? How else can I do it? Can we avoid changing the document structure?