本文介绍了findOne在服务器上返回未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我在服务器上的代码:
Here is my code on the server:
Meteor.publish('currentRequest', function (requestId) {
console.log('from publish');
console.log(requestId) // The id is printed successfully
console.log(Requests.findOne({_id: requestId})) // returns undefined
return Requests.findOne({_id: requestId});
});
已打印项目ID,但.findOne()
似乎不起作用,因为它返回undefined
.
The item ID is printed but .findOne()
doesn't seem to work as it returns undefined
.
我在做什么错了?
推荐答案
您的问题的答案将是:因为没有满足您的搜索查询的文档.
The answer to your question will be: because there is no document satisfying your search query.
根据文档:
等同于find(selector, options).fetch()[0]
与options.limit = 1
.
此外,正如@GaëtanRouziès指出的那样,该出版物将不起作用,因为.findOne
返回document/undefined
而不是光标.
Also, as it has been pointed by @GaëtanRouziès, this publication won't work, because .findOne
returns document/undefined
instead of cursor.
这篇关于findOne在服务器上返回未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!