import '../imports/api/classes/Customer';
import '../imports/api/classes/Brand';
// In your schema definition, add event beforeInsert:
events: {
beforeInsert(e) {
const latest = XXX.findOne({}, {
sort: { YYY: -1 },
});
e.currentTarget.YYY = (typeof latest === 'undefined') ? 1 : latest.YYY + 1;
},
},
...
import MongoCounters from 'mongodb-counter';
// Setup the counters object used for auto-incrementing
const path = `${process.env.PWD}/pm2-meteor.json`;
const json = fs.readFileSync(path, 'utf8');
const config = JSON.parse(json);
const counters = MongoCounters.createCounters({
mongoUrl: config.env.MONGO_URL
});
const Invoice = Class.create({
...
events: {
beforeInsert(e) {
const invoice = e.currentTarget;
// Wrap the counters increment and get method so they're
// synchronous. I tried to use the callback methods as
// in the docs for mongo-counter, but it didnt work
Meteor.wrapAsync(counters('invoiceId').increment)();
const nextId = Meteor.wrapAsync(counters('invoiceId').get)();
if (typeof nextId === 'number') {
invoice.invoiceId = nextId;
}
}
},
...
// Define FileStatus enum.
const FileStatus = Enum.create({
name: 'FileStatus',
identifiers: ['TEMPORARY', 'PERMANENT'],
});
// Inside schema definition.
status: {
type: FileStatus,
default: FileStatus.TEMPORARY,
},
helpers: {
children() {
// Lấy danh sách tất cả users theo referrerId
const children = User.find({ referrerId: this._id }).fetch()
return children
},
childrenCount() {
return this.children().count()
}
},
behaviors: {
timestamp: {
hasCreatedField: true,
createdFieldName: 'createdAt',
hasUpdatedField: true,
updatedFieldName: 'updatedAt'
}
}
user .children()
is children is not function
{ modified: true }
is implemented in the validate()
function, but I can't find anything in the docs or the code. Is it not implemented? How could I use such a feature? It would greatly benefit the performance of my app
$unset: { temp: '' }
but it seems that Astronomy is not allowing this operation to happen. I'm wondering what the equivalent is. Please that I don't want to set it to false
or null
, I want the field being deleted from my collection. Thanks in advance for your help!