var self = this;
var itemCount = 0;
myCollection.find() //unfiltered find because we need to observe all the fields
.observeChanges({
changed: function (id, field) {
var raw_document = myCollection.findOne({_id: id});
switch (field) {
case "item":
itemCount = raw_document.item.length;
break;
default:
}
}
})
.forEach(function (entry) { //I iterate on each document in order to add its item_count field
self.added("item_count", entry._id, raw_document.item.length);
})
.find({}, { item: 0 }) // I filter my item array
// I update the values in case a change has been observed
self.added("item_count", entry._id, itemCount);
self.ready();`
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.