2013-08-02 55 views
0

我有一个流星项目中,我有以下集合:查询子文档不工作

problems = new Meteor.Collection("Problems") 

一个问题的文件是这样的:

problems.insert({Problem:{Message:m, Patient_name:p_name, Request:req}, DateStamp:datecntr}); 

现在我想找到请求等于给定值的所有问题。因此,我有以下功能:

Template.history_list.histories = function() { 
return problems.find({Problem:{$elemMatch:{Request:Session.get('history_label')}}}); 
}; 

在模板我有这样的事情

<template name="history_list"> 
{{#each histories}} 
{{Problem.Message}}<br> 
{{/each}} 
</template> 

我曾尝试不同的建筑用我的查询,但没有任何工程。我在mongodb.org上搜索并找到了您在此查看的用于查询subdoc的构造,但不幸的是,它不起作用。

有人可以帮忙吗?

感谢

回答

1

$elemMatch用于数组,你没有一个。在你的情况下,这应该工作:

Template.history_list.histories = function() { 
    return problems.find({ 'Problem.Request': Session.get('history_label') }); 
}; 
+0

谢谢!这是正确的。 – Quantum