Mongodb 即使在meteor中自动发布,客户端也无法获取集合
/lib/collection.jsMongodb 即使在meteor中自动发布,客户端也无法获取集合,mongodb,meteor,Mongodb,Meteor,/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', },
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()
返回空对象
自动发布尚未删除。因此,我无法获取错误。这只是因为数据到达客户端需要一定的时间。在您的
/client/index.js中这样尝试
import { Meteor } from 'meteor/meteor';
import { Tracker } from 'meteor/tracker';
import {Chats} from '../lib/collections'
Tracker.autorun( () => console.log( Chats.find() ) );
你忘了发布收藏并订阅它了吗?它将在客户端上不可用,直到稍有延迟。使用发布时,可以在订阅准备就绪时触发回调,通知您的数据现在在客户端上可用。