我是Meteor的新手所以我一直在玩,现在我已经遇到了这个问题.
我正在使用React Router尝试显示基于URL /(:userId)的主题.如果没有userId插入到URL中,它应该显示当前用户的主题,如果没有当前用户,则应该显示默认主题.
它随机工作.有时我会得到正确的主题,有时候在读取themeColor时会抛出未定义的内容,即使数据存在.我可以通过console.log看到它总是得到正确的ID,但仍然findOne可以抛出undefined.当我更改URL(/ xyz)并返回默认值(/)时,会发生这种情况.
我在控制台验证了userId是themeColor和themeTextColor的实际拥有者.
我正在使用React,React-router,autopublish.我删除了不安全的东西.
getMeteorData() {
var currentViewedPageId = this.props.params.userId? this.props.params.userId:(Meteor.userId()?Meteor.userId():false);
console.log(currentViewedPageId); //Allways right
console.log(Personalization.findOne({owner: currentViewedPageId}).themeColor); //Sometimes undefined, sometimes not
if(currentViewedPageId)
{
return {
currentUser: Meteor.user(),
themeColor: Personalization.findOne({owner: currentViewedPageId}).themeColor,
themeTextColor: Personalization.findOne({owner: currentViewedPageId}).themeTextColor
};
}
return {
currentUser: Meteor.user()
}
},
Run Code Online (Sandbox Code Playgroud) 数据库操作插入现在似乎是在插入后立即同步返回_id,因此这里不需要回调.
问题在于_id生成(和检查)的位置,因为这似乎是在miniMongo上完成的快速同步动作,但是没有某个集合的_id的完整列表,miniMongo如何检查是否可以_id是重复还是没有?
当我在客户端和服务器上执行Meteor.call而不是直接收集操作时.它是否会删除乐观的UI更改,即最小化更改,只是直接更改服务器并在更新UI之前等待服务器上的更新?
我有一个Meteor方法,我从客户端调用,然后更新单个文档中的所有字段.在下面的最后一行代码中,我尝试立即在客户端上运行相同的更新以获得直接的副作用(它假设更新将通过).我得到的麻烦是:
更新失败:访问被拒绝.在受限制的集合中,您只能更新文档,而不能替换它们.使用Mongo更新运算符,例如'$ set'
当试图这样做.我不想更新单个字段,我想更新整个文档.有没有办法正确地做到这一点?
entry = {
title: title
text: text
tags: entry.tags
mode: $('#mode').val()
file_ids: entry.file_ids
}
eid = Session.get('entryId')
entry._id = eid if eid
context = Session.get('context')
Meteor.call('saveEntry', title, entry, context)
Entries.update({_id: entry._id}, entry)
Run Code Online (Sandbox Code Playgroud) 我需要对“日期时间”升序格式进行排序。但是得到一个错误“ Requests.find(...).sort is not a function”meteor mini mongo find
var results = Requests.find({
"sp_id": request.sp_id,
"slot": request.slot,
"date": request.date,
"datetime": {
'$gte': request.datetime
},
"status": {
$nin: ['cancel', 'completed']
}
}
).sort({datetime: 1}).fetch();
console.log(results);
Run Code Online (Sandbox Code Playgroud)
谢谢。