title: Meteor return length of array in mongodb
body: <p>In my users profile collection I have array with image objects in it. </p>
  
  <p>A user can have a max of 3 images in their profile collection. If the user has 3, throw an error that the maximum has been reached. The user has the option to remove an image themselves in the frontend. </p>
  
  <p>I thought the solution would be to check the length of the array with $size. if it's less then 3, insert the image, else throw error.</p>
  
  <p>I'm using the tomi:upload-jquery package.</p>
  
  <p>client:</p>
  
  <pre><code>  Template.uploadImage.helpers({
      uploadUserData: function() {
          return Meteor.user();
      },
      finishUpload: function() {
          return {
              finished: function(index, fileInfo, context) {
  
                  Meteor.call('insert.profileImage', fileInfo, function(error, userId) {
                      if (error) {
                          // todo: display modal with error
                          return console.log(error.reason);
                      } else {
                          // console.log('success ' +userId);
                          // console.log('success ' + fileInfo);
                      }
                  });
              }
          };
      }
  });
  </code></pre>
  
  <p>The method (server) I use:</p>
  
  <pre><code>'insert.profileImage': function(postImage) {
      check(postImage, Object);
  
      // check array profile.images max 3
  
      Meteor.users.update(this.userId, {
          $push: {
              'profile.images': postImage
          }
      });
  },
  </code></pre>