function runProgramLogic() {
  var users = db.getCollection("users");
  var ov500 = users.getDynamicView("over 500");

  // generate random number between 1-1000
  // since our view is 'over500' there is 50% change it will be
  // in our dynamic view results
  var randomAge = Math.floor(Math.random() * 1000) + 1;
  // another 50% chance of being male
  var randomGender = Math.floor(Math.random() * 2);

  var newUser = {
    name : "user #" + users.count(),
    age : randomAge,
    gender : (randomGender?"m":"f")
  }

  console.log("");
  console.log("adding user : ");
  console.log(newUser);
  console.log("");

  users.insert(newUser);

  let result = ov500.data();
  console.log("'over 500' dynamic view results : ");
  console.log(result);
  console.log("");

  // now let's take our 'generic' bulk filtering dynamic view and further query its 'current' results
  // to find only the gender 'm' users in the dynamic view results.
  result = ov500.branchResultset().find({gender: 'm'}).data();
  console.log("over 500 males : ");
  console.log(result);
  console.log("");
  
  // branchResultset can also take transforms if you want to craft frequently used transformations
  // on view results... see the wiki page on collection transforms for examples of that if interested.

  console.log("press ctrl-c to quit");

}
Logic to run after database is initialized

Our example program will add one document each time this program is run.
We will then dump the view so you can see if it passed the view filter.