Skip to content

Latest commit

 

History

History
45 lines (36 loc) · 1.25 KB

find.md

File metadata and controls

45 lines (36 loc) · 1.25 KB

find([selector, options]) [Isomorphic]

Find and return Cursor for matching documents.

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

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

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

// Get Mongo cursor:
Meteor.publish('images', function() {
  imagesCollection.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:
imagesCollection.collection.remove();

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