Skip to content
dr.dimitru edited this page Jul 22, 2018 · 5 revisions
find([selector, options]) [Isomorphic]

Find and return Cursor for matching documents.

import { Meteor }          from 'meteor/meteor';
import { FilesCollection } from 'meteor/ostrio:files';

const Images = new FilesCollection({collectionName: 'Images'});

// Usage:
// Set cursor:
const filesCursor = Images.find();

// Get Mongo cursor:
Meteor.publish('images', function() {
  Images.find().cursor;
});

// Get cursor's data:
filesCursor.fetch();
// Get cursor's data (alternative):
filesCursor.get();

// Remove all cursor's records and associated files:
filesCursor.remove(function (error) {
  if (error) {
    console.error('File(s) is not removed!', error);
  }
});
// Remove only Collection records from DB:
Images.collection.remove();

// Each:
filesCursor.each(function (file) {
  // Only available in .each():
  file.link();
  file.remove();
  file.with(); // <-- Reactive object
});
Clone this wiki locally