I tried to pass the collection to be update as a scope variable - no dice.
I tried to invoke db.getCollection
from the finalize body - no dice, I get this:
db assertion failure, assertion: 'invoke failed: JS Error: TypeError: db has no properties nofile_b:18', assertionCode: 9004
I guess it means that db
is undefined within a finalize method. So, is it possible?
EDIT
Here is my finalize method:
function(key, value) {
function flatten(value, collector) {
var items = value;
if (!(value instanceof Array)) {
if (!value.items) {
collector.push(value);
return;
}
items = value.items;
}
for (var i = 0; i < items.length && collector.length < max_group_size; ++i) {
flatten(items[i], collector);
}
}
var collector = [];
flatten(value, collector);
return collector;
}
I would like to replace collector.push(value)
with insert into some collection.