Skip to content

Instantly share code, notes, and snippets.

@boxofrox
Last active October 15, 2015 00:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boxofrox/3c630cfbf4eea4ac8198 to your computer and use it in GitHub Desktop.
Save boxofrox/3c630cfbf4eea4ac8198 to your computer and use it in GitHub Desktop.
Meteor Test: find docs in collection where array field contains any value in a set.

How to run:

  1. establish a meteor environment.
    cd /tmp
    meteor create app
  1. init git.
    cd /tmp/app
    git init
  1. pull sources from gist
    git remote add gist <gist clone url>
    git fetch gist
    git checkout -f master
    git clean -f
  1. run app. only outputs to server console.
    meteor
var Things = new Mongo.Collection('things');
if (Meteor.isServer) {
Meteor.startup(function () {
Things.remove({});
Things.insert({ roles: [1, 2, 3] });
Things.insert({ roles: [4, 5, 6] });
Things.insert({ roles: [7, 8, 9] });
Things.insert({ roles: [1, 4, 7] });
Things.insert({ roles: [2, 5, 8] });
Things.insert({ roles: [3, 6, 9] });
var out = Things.find({ roles: { $in: [1, 3, 4] } }).fetch();
console.log('find roles with', [1, 3, 4]);
console.log('in', Things.find().fetch());
console.log('result', out);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment