Skip to content

findOne

dr.dimitru edited this page Jul 22, 2018 · 6 revisions
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 Images = new FilesCollection({collectionName: 'Images'});

// Usage:
// Set cursor:
const file = Images.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:
Images.collection.findOne({_id: 'Rfy2HLutYK4XWkwhm'});
// Remove record from collection:
Images.collection.remove({_id: 'Rfy2HLutYK4XWkwhm'});