-
-
Notifications
You must be signed in to change notification settings - Fork 169
findOne
dr.dimitru edited this page Jul 22, 2018
·
6 revisions
Finds the first document that matches the selector, as ordered by sort and skip options.
-
selector
{String|Object} - Mongo-Style selector -
options
{Object} - Mongo-Style selector Options - Returns {FileCursor}
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'});
Meteor-Files | Support | Try ostr.io |
---|---|---|
If you found this package useful, — star it at GitHub and support our open source contributions with a monthly pledge, or submit a one-time donation via PayPal | Monitoring, Analytics, WebSec, Web-CRON and Pre-rendering for a website |