我正在经历我的第一个Meteor构建,我到了某个角落然后撞到了墙上。我无法访问我的集合,起初我认为这是我的查询语法的问题,但我认为不是。
我尝试过:db.collection.find()
并且它在Mongo shell中按预期工作,但在客户端中,db.collection.find()
返回LocalCollection.Cursor
,它只是给我一个函数和原型的列表与当前集合相关联。
db.collection.find().fetch()
只返回{}
。
更多信息:我安装了 admin-ui ,我通过它设置了架构。当前用户为Admin,已分配管理员角色。
提前感谢您的帮助。我正试着调试这个问题。
答案 0 :(得分:1)
的核对表我无法在Meteor问题中查看我的数据:
$ meteor add autopublish
型:
console.log('My subscription has '+myCollection.find().count()+' documents!");
在您的浏览器控制台中。
服务器:
Meteor.publish('myPublication',function(){
return myCollection.find(); // or whatever subset you want for this user
});
客户端:
var handle = Meteor.subscribe('myPublication');
$ meteor remove autopublish
ready()
状态来完成。代码:
if ( handle.ready() ) {
console.log('My subscription has '+myCollection.find().count()+' documents!");
}
答案 1 :(得分:0)
Mongo有一个专门用于mongodb操作的API,它与mongodb自己的API略有不同。
在流星世界,你首先要定义一个集合" (以最基本的形式在服务器和客户端上)
MyCollection = new Mongo.Collection('mycollection');
现在默认情况下,这最终会在名为" meteor"的数据库中结束。一个名为" mycollection"
的集合插入:
MyCollection.insert({foo: "bar"});
要查询,假设您没有删除" autopublish"来自您的应用程序的包
MyCollection.find();
现在返回一个"光标"不是一个数组,所以要将它映射到一个数组,你做
MyCollection.find().fetch();
然而在mongo shell上,你会完成
use meteor
db.mycollection.find()
答案 2 :(得分:0)
所以,经过一番思考,我意识到我应该解决与我的问题有关的问题,也许我是个白痴,但我学到了很多东西:
以下是我的帮助程序的代码:
myFunction: function () {
// get from array the date we need and its ISOdate
selector = Session.get("myCalendarArray");
today = selector.month[dayPointer];
today = today["ISOdate"];
// set the date for tomorrow, in this case the dates are set at 12:00AM,
// so we actually only need half way through the day.
tomorrow = new Date();
tomorrow = tomorrow.setDate(today.getDate() + .5);
return MyCollection.find( { releaseDate : { $gte : new Date(today), $lte : new Date(tomorrow) } } ).fetch()
}
所以我最终要解决的问题是:
new Date(today)
是从数据库中选择日期的正确方法$ date不起作用。