在下面的数据中,我想找到_id=abc1
和月份为1
的提醒。存储在db中的日期是文本。
我尝试使用此命令,但它有错误:
db.check.find({_ id:“abc1”},{提醒:{$ regex:{date:2015-1 /}}}) 。漂亮();
我该怎么做? 预期结果为{date:“2005-1-5”,event:“MeetingB”},{date:“2005-1-4”,event:“MeetingA”}
{
_id: "abc1", reminder:[ { date: "2005-1-5", event: "MeetingB" }, { date: "2005-1-4", event: "MeetingA" }, { date: "2005-2-4", event: "MeetingA" } ] }
{
_id: "abc2", reminder:[ { date: "2005-1-5", event: "MeetingB" } ]
}
答案 0 :(得分:0)
它认为你有2个解决方案:
aggregate
你在另一个搜索中得到的
只有一个月。 使用这个例子(我没有测试过,但看起来应该是这样的):
db.check.find( {
$and: [
{ "_id": { $in: ["abc1"] } },
{ "reminder.date": { $in: [/2005-1*/] } }
]
} );
您无法在in
中使用regex
而必须使用JavaScript regex
然而,它会返回完整的对象,而不是显然你想要的部分对象。