Meteor发布/订阅错误

时间:2016-09-15 02:01:55

标签: javascript mongodb meteor reactjs

以下是我的文件: tasks.js

import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import { check } from 'meteor/check';

export const Tasks = new Mongo.Collection('tasks');

if(Meteor.isServer) {
    Meteor.publish('tasks', function tasksPublication() {
        return Tasks.find();
    });
}

TasksList.jsx

import Tasks from '../../api/tasks.js';
import { createContainer } from 'meteor/react-meteor-data';
...
TasksList.propTypes = {
    tasks: PropTypes.array.isRequired,
}
...
export default createContainer(() => {
    Meteor.subscribe('tasks');
    return {
        tasks: Tasks.find({}, {sort: {createdAt: -1}}).fetch(),
    };
}, TasksList);

服务器:main.js

import '../imports/api/tasks';

我收到此错误:

Uncaught TypeError: Tasks.find is not a function

在这一行

tasks: Tasks.find({}, {sort: {createdAt: -1}}).fetch(),

我不能在哪里出错,一切对我来说都很正常......

1 个答案:

答案 0 :(得分:0)

我解决了它: 它应该是:

import {Tasks} from '../../api/tasks.js';