How to return the number of items in the collection?


I'm new to Meteor and I want to create a slideshow with items from a collection, in this case simple words. The slideshow should be controlled by back and forward buttons and replace the current word.

In JavaScript/jQuery I would create an array of objects and a control index, with limits via if-statements, so the index never can drop below zero or overflow the length of the array.

See fiddle for working example:

$(document).ready(function() {
var wordArray = ["hello", "yes", "no", "maybe"];
var arrayIndex = 0;


    if (arrayIndex > 0) {
     arrayIndex -= 1;


    if (arrayIndex < wordArray.length) {
                arrayIndex += 1;




I'm curious how to implement this in regards to best practice in meteor and abide to the reactive pattern as I'm still trying to wrap my head around this interesting framework. My first hurdle is to translate the

if (arrayIndex < wordArray.length)
// to
if (Session.get("wordIndex") < ( (((length of collection))) )

According to the docs I should do a find on the collection, but I have only manage to return an empty array later with fetch. Sorry if this got long, but any input would be appreciated to help me figure this out.

collection.find([selector], [options])

This is the code I have so far:

Words = new Mongo.Collection("words");

if (Meteor.isClient) {

  // word index starts at 0
  Session.setDefault("wordIndex", 0);

    words: function () {
      return Words.find({});
    wordIndex: function () {
      return Session.get("wordIndex");
      "submit .new-word": function (event) {
        // This function is called when the word form is submitted
        var text =;

          text: text,
          createdAt: new Date() //current time

        // Clear form = "";

        // Prevent default form submit
        return false;
      'click #previous': function () {
        // decrement the word index when button is clicked
        if (Session.get("wordIndex") > 0) {
          Session.set("wordIndex", Session.get("wordIndex") - 1);
      'click #next': function () {
        // increment the word index when button is clicked
          if (Session.get("wordIndex") < 10 ) {
          Session.set("wordIndex", Session.get("wordIndex") + 1);




if (Meteor.isServer) {
  Meteor.startup(function () {


.count() will return the number of documents in a collection.