蒙戈查询和操作
问题描述:
在我的流星的应用程序,我想算的基于两个字段集合项数,没有成功:蒙戈查询和操作
importantTilDatesCount: Entrys.findFromPublication('importantEntrys', { $and: [
{"importantType" : { true }},
{"importantDate" : {
$lt: new Date(new Date().setDate(new Date().getDate()+7))
}}
]
}).count(),
“进”是没有错字;)
答
谢谢,它是两个。 true
而不是{ true }
,以及不指定$and
。
看起来你只是想'真'而不是'{真}' – rubie
你也几乎从不需要'$和'。因此,您的查询是'{“importantType”:true,“importantDate”:{“$ lt”:new Date(new Date()。setDate(new Date()。getDate()+ 7))}}'。你只需要指定'$和'你必须在同一个“键”上绝对放置多个条件。即使这样,你经常不需要它。即'{“date”:{“$ gt”:昨天,“$ lte”:today}}'实际上只是AND表达式的另一种形式。 –