1.在server-sales/lib/collections目录下创建DownloadRecords.js文件
import { Mongo } from 'meteor/mongo';
const DownloadRecords = new Mongo.Collection('downloadRecords');
DownloadRecords.schema = new SimpleSchema({
dowoloadInfo: {
label: '下载信息',
type: [Object], // 数组对象
optional: true, // 可选项,在插入时如果没有这个参数则dowoloadInfo必传
},
status: {
label: '下载次数',
type: Number,
defaultValue: 0, // 设置默认值
},
fileName: {
label: '文件名',
type: String,
},
});
DownloadRecords.attachSchema(DownloadRecords.schema);
export default DownloadRecords;
2.在server-sales/lib/index.js文件中导出所有数据表格
import DownloadRecords from './collections/DownloadRecords.js';
export default {
DownloadRecords,
};
3.在server-sales/server/methods文件夹中新建DownloadRecord.js文件
import Collections from '/lib';
export default () => {
// 插入一条下载记录数据
new ValidatedMethod({
name: 'DownloadRecords.methods.insertRecord',
validate: null,
run({ userId, condition }) {
const userIds = {
userId: userId,
downloadAt: new Date(),
}
const data = Object.assign(userIds, condition);
// Collections.GuestOrder.insert(data)
return Collections.DownloadRecords.insert(data);
},
});
};
4.在server-sales/server/methods/index.js中导出方法,让前台能够调用。
import DownloadRecord from './DownloadRecord';
export default () => {
DownloadRecord();
};
5.client(前端调用方法DownloadRecords.methods.insertRecord),该方法在actions文件夹中
insertDownloadRecord({ _Meteor }, condition) {
_Meteor.call('DownloadRecords.methods.insertRecord', { userId: Meteor.userId(), condition }, (err, result) => {
console.log(err, result);
});
},
前端download(下载内容)连接服务端方法文件:server-sales/server/restapi/download 以及 server-sales/server/methods/data
前端方法以及调用报错参考以下链接。
http://www.jianshu.com/p/6a166843a62a
MongoDB基本操作(聚集集合查询)以及server端查找更新删除方法。
http://520b5e68.wiz03.com/share/s/1i2RVE0TTQNu2WoVi33UpVSn3tuVSF2w9kbu2jmrWX1EhsOK