Template.CompanyEntry.helpers({
companies: function() {
var Company= Companies.find();
console.log (Company);
var id = Company._id;
Session.set('CurrentCompany',id);
alert (Session.get('CurrentCompany'));
return Company;
}
})
我正在尝试从文档中读取特定值。我该怎么做?
答案 0 :(得分:1)
喜欢这个。
var CompanyId = Companies.findOne({TargetName: TargetValue}, {fields: {_id: 1});
var id = CompanyId._id;
或者如果你不想使用findOne,因为find更有效
var CompanyArray = Companies.find({TargetName: TargetValue}, {fields: {_id: 1}, limit: 1}).fetch();
var id = CompanyArray[0]['_id'];