/lib/collection.js
import { Mongo} from 'meteor/mongo';
export const Chats = new Mongo.Collection('chats');
/server/app.js
import { Chats} from '../lib/collections';
const chats = [
{
text: 'You on your way?',
},
{
text: 'Hey, it\'s me',
},
{
text: 'I should buy a boat',
},
{
text: 'Look at my mukluks!',
},
{
text: 'This is wicked good ice cream.',
}
];
chats.forEach(function(chat)
{
Chats.insert(chat);
})
/client/index.js
import { Meteor } from 'meteor/meteor';
import {Chats} from '../lib/collections'
console.log(Chats.find());
为什么Chats.find()
返回空对象?
自动发布尚未删除。所以我无法得到错误。
答案 0 :(得分:1)
这仅仅是因为数据需要一定的时间才能到达客户端。在您的/client/index.js
import { Meteor } from 'meteor/meteor';
import { Tracker } from 'meteor/tracker';
import {Chats} from '../lib/collections'
Tracker.autorun( () => console.log( Chats.find() ) );