[英]find object from mongodb
在下面的數據中,我想找到_id=abc1
且月份為1
的提醒。 db中存儲的日期是文本。
我嘗試使用此命令,但有錯誤:
db.check.find({_id:“ abc1”},{提醒:{$ regex:{date:2015-1 /}}}).pretty();
我該怎么做?
預期的結果是{日期:“ 2005-1-5”,事件:“ MeetingB”},{日期:“ 2005-1-4”,事件:“ 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" } ]
}
它認為您有2個解決方案:
aggregate
到另一個中,僅獲得月份。 在這個例子中(我還沒有測試過,但是看起來應該像這樣):
db.check.find( {
$and: [
{ "_id": { $in: ["abc1"] } },
{ "reminder.date": { $in: [/2005-1*/] } }
]
} );
您不能在in
使用regex
,而必須使用JavaScript regex
但是,它將返回完整的對象,而不是顯然要返回的部分對象。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.