undefined不是一个函数(评估' _reactNativeMeteor2.default.collection(" messages")。find()。fetch()')

时间:2016-12-17 05:03:32

标签: mongodb reactjs meteor react-native react-native-router-flux

在我的Meteor应用程序中,我有一个像这样的集合定义:

this.collections.Messages = new Mongo.Collection("messages");

现在我尝试从react native meteor这样连接到它:

import React, { Component } from 'react';
import Meteor, { createContainer } from 'react-native-meteor';
import MessageListComponent from '../routes/messageList';

export default MessageListContainer = createContainer(() => {
    const messagesHandle = Meteor.subscribe('userMessage');
    const loading = !messagesHandle.ready();
    const messages = Meteor.collection("messages").find().fetch();
    return {
        loading,
        messages
    };
}, MessageListComponent);

但它在设备上返回红色错误消息:

undefined is not a function (evaluating '_reactNativeMeteor2.default.collection("messages").find().fetch()')

男人有什么问题?

1 个答案:

答案 0 :(得分:1)

尝试从消息const中删除fetch():

const messages = Meteor.collection('messages').find();

fetch将光标转换为数组,这里可能不需要。此外,这一行是唯一一个双引号的行,但我不确定这是否相关。