Skip to content

Latest commit

History

History
38 lines (31 loc) 路 1.27 KB

findOne.md

File metadata and controls

38 lines (31 loc) 路 1.27 KB

findOne([selector, options]) [Isomorphic]

Finds the first document that matches the selector, as ordered by sort and skip options.

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

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

// Usage:
// Set cursor:
const file = imagesCollection.findOne({_id: 'Rfy2HLutYK4XWkwhm'});
// Generate downloadable link:
file.link();
// Get cursor's data as plain Object:
file.get();
file.get('_id'); // <-- returns sub-property value, if exists
// Get cursor's data as reactive Object
file.with();
// Get cursor as array:
file.fetch();
// Remove record from collection and file from FS
file.remove(function (error) {
  if (error) {
    console.error('File wasn\'t removed', error);
  }
});


// Direct Collection usage:
imagesCollection.collection.findOne({_id: 'Rfy2HLutYK4XWkwhm'});
// Remove record from collection:
imagesCollection.collection.remove({_id: 'Rfy2HLutYK4XWkwhm'});