-
-
Notifications
You must be signed in to change notification settings - Fork 169
Schema
dr.dimitru edited this page Jul 22, 2018
·
10 revisions
Below is default Files collection schema. Please keep default schema structure when extending it!. To pass your own schema use schema
property when passing config to FilesCollection
constructor.
For more info see Collection2 and simple-schema packages.
const defaultSchema = {
_id: {
type: String
},
size: {
type: Number
},
name: {
type: String
},
type: {
type: String
},
path: {
type: String
},
isVideo: {
type: Boolean
},
isAudio: {
type: Boolean
},
isImage: {
type: Boolean
},
isText: {
type: Boolean
},
isJSON: {
type: Boolean
},
isPDF: {
type: Boolean
},
extension: {
type: String,
optional: true
},
ext: {
type: String,
optional: true
},
extensionWithDot: {
type: String,
optional: true
},
mime: {
type: String,
optional: true
},
'mime-type': {
type: String,
optional: true
},
_storagePath: {
type: String
},
_downloadRoute: {
type: String
},
_collectionName: {
type: String
},
public: {
type: Boolean,
optional: true
},
meta: {
type: Object,
blackbox: true,
optional: true
},
userId: {
type: String,
optional: true
},
updatedAt: {
type: Date,
optional: true
},
versions: {
type: Object,
blackbox: true
}
};
Although this package comes with schema it isn't enabled (attached) by default (since v1.5.0), you're free to use it or not. To attach schema you need to install Collection2 and simple-schema packages separately.
import { FilesCollection } from 'meteor/ostrio:files';
const Images = new FilesCollection({ collectionName: 'Images'});
Images.collection.attachSchema(new SimpleSchema(Images.schema));
The default schema is available as a static property of FilesCollection
, so you can extend it using a library like underscore:
import { FilesCollection } from 'meteor/ostrio:files';
const mySchema = Object.assign({}, FilesCollection.schema, {
myProp: {
type: String
}
});
const Images = new FilesCollection({
collectionName: 'Images',
schema: mySchema
});
Images.collection.attachSchema(new SimpleSchema(mySchema));
Or with ES6 object spread syntax:
import { FilesCollection } from 'meteor/ostrio:files';
const mySchema = {
...FilesCollection.schema,
myProp: {
type: String
}
};
const Images = new FilesCollection({
collectionName: 'Images',
schema: mySchema
});
Images.collection.attachSchema(new SimpleSchema(mySchema));
import { FilesCollection } from 'meteor/ostrio:files';
const mySchema = { /* Your schema here */ };
const Images = new FilesCollection({
collectionName: 'Images',
schema: mySchema
});
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 |