您好我是Mongo DB的新手,并尝试从它开始,我创建了一个集合并将此文档插入其中
grade.properties
}
现在我正试图通过日期查找此查询
{
"_id" : ObjectId("574ad7c42368e58f8c07a47d"),
"id" : 10000,
"BookieId" : 1,
"EventBookieId" : null,
"LeagueId" : 214,
"LeagueNameId" : 4571,
"Team1Id" : 435,
"Team1NameId" : null,
"Team2Id" : 430,
"Team2NameId" : null,
"EventDateTime" : "2013-09-14T14:00:00",
"isNew" : true,
"CountryId" : 36,
"isCountry" : true,
"isLeague" : true,
"Gameid" : null,
"Reversed" : false,
"eventId" : 10000,
"bets" : [
{
"id" : 1,
"EventConnectionId" : 10000,
"isCorners" : false,
"DateTime" : "2013-09-10T09:06:43.333",
"IsLive" : false,
"Team1Score" : null,
"Team2Score" : null,
"Team1RedCards" : null,
"Team2RedCards" : null,
"odds" : []
},
{
"id" : 2,
"EventConnectionId" : 10000,
"isCorners" : false,
"DateTime" : "2013-09-10T19:50:26.84",
"IsLive" : false,
"Team1Score" : 0,
"Team2Score" : 0,
"Team1RedCards" : null,
"Team2RedCards" : null,
"odds" : [
{
"id" : 62282718,
"BetId" : 2,
"BookieId" : 1,
"BookieBetId" : "21968173",
"ScrapingDateTime" : "2013-09-13T08:39:15.81",
"MinuteInGame" : null,
"GamePart" : null,
"Odds1" : 1.81,
"Odds2" : 2.1236,
"Odds3" : null,
"MaxBet" : 2000,
"Bet" : "Hcap",
"BetGamePart" : 0,
"Line" : -0.25,
"ID_IDENTITY" : 1
},
{
"id" : 62282719,
"BetId" : 2,
"BookieId" : 1,
"BookieBetId" : "21968175",
"ScrapingDateTime" : "2013-09-13T08:39:15.81",
"MinuteInGame" : null,
"GamePart" : null,
"Odds1" : 2.04167,
"Odds2" : 1.86,
"Odds3" : null,
"MaxBet" : 2000,
"Bet" : "Total",
"BetGamePart" : 0,
"Line" : 2.0,
"ID_IDENTITY" : 2
},
{
"id" : 62282720,
"BetId" : 2,
"BookieId" : 1,
"BookieBetId" : "21968177",
"ScrapingDateTime" : "2013-09-13T08:39:15.81",
"MinuteInGame" : null,
"GamePart" : null,
"Odds1" : 2.16,
"Odds2" : 3.45,
"Odds3" : 3.05,
"MaxBet" : 1000,
"Bet" : "X12",
"BetGamePart" : 0,
"Line" : null,
"ID_IDENTITY" : 3
},
{
"id" : 62282721,
"BetId" : 2,
"BookieId" : 1,
"BookieBetId" : "21968179",
"ScrapingDateTime" : "2013-09-13T08:39:15.81",
"MinuteInGame" : null,
"GamePart" : null,
"Odds1" : 2.21951,
"Odds2" : 1.7,
"Odds3" : null,
"MaxBet" : 1000,
"Bet" : "Hcap",
"BetGamePart" : 1,
"Line" : -0.25,
"ID_IDENTITY" : 4
},
{
"id" : 62282722,
"BetId" : 2,
"BookieId" : 1,
"BookieBetId" : "21968180",
"ScrapingDateTime" : "2013-09-13T08:39:15.81",
"MinuteInGame" : null,
"GamePart" : null,
"Odds1" : 2.78,
"Odds2" : 3.9,
"Odds3" : 1.99,
"MaxBet" : 500,
"Bet" : "X12",
"BetGamePart" : 1,
"Line" : null,
"ID_IDENTITY" : 5
},
{
"id" : 62282723,
"BetId" : 2,
"BookieId" : 1,
"BookieBetId" : "21968181",
"ScrapingDateTime" : "2013-09-13T08:39:15.81",
"MinuteInGame" : null,
"GamePart" : null,
"Odds1" : 1.93,
"Odds2" : 1.95,
"Odds3" : null,
"MaxBet" : 1000,
"Bet" : "Total",
"BetGamePart" : 1,
"Line" : 0.75,
"ID_IDENTITY" : 6
},
{
"id" : 62290838,
"BetId" : 2,
"BookieId" : 1,
"BookieBetId" : "14382209",
"ScrapingDateTime" : "2013-09-13T15:38:11.303",
"MinuteInGame" : null,
"GamePart" : null,
"Odds1" : 1.81,
"Odds2" : 2.1236,
"Odds3" : null,
"MaxBet" : 2000,
"Bet" : "Hcap",
"BetGamePart" : 0,
"Line" : -0.25,
"ID_IDENTITY" : 7
},
{
"id" : 62290839,
"BetId" : 2,
"BookieId" : 1,
"BookieBetId" : "14382211",
"ScrapingDateTime" : "2013-09-13T09:27:39.6",
"MinuteInGame" : null,
"GamePart" : null,
"Odds1" : 2.05263,
"Odds2" : 1.85,
"Odds3" : null,
"MaxBet" : 2000,
"Bet" : "Total",
"BetGamePart" : 0,
"Line" : 2.0,
"ID_IDENTITY" : 8
},
{
"id" : 62290840,
"BetId" : 2,
"BookieId" : 1,
"BookieBetId" : "14382213",
"ScrapingDateTime" : "2013-09-13T10:29:22.863",
"MinuteInGame" : null,
"GamePart" : null,
"Odds1" : 2.15,
"Odds2" : 3.45,
"Odds3" : 3.1,
"MaxBet" : 1000,
"Bet" : "X12",
"BetGamePart" : 0,
"Line" : null,
"ID_IDENTITY" : 9
},
{
"id" : 62290841,
"BetId" : 2,
"BookieId" : 1,
"BookieBetId" : "14382215",
"ScrapingDateTime" : "2013-09-13T15:38:11.303",
"MinuteInGame" : null,
"GamePart" : null,
"Odds1" : 2.21951,
"Odds2" : 1.7,
"Odds3" : null,
"MaxBet" : 1000,
"Bet" : "Hcap",
"BetGamePart" : 1,
"Line" : -0.25,
"ID_IDENTITY" : 10
},
{
"id" : 62290842,
"BetId" : 2,
"BookieId" : 1,
"BookieBetId" : "14382216",
"ScrapingDateTime" : "2013-09-13T15:38:11.303",
"MinuteInGame" : null,
"GamePart" : null,
"Odds1" : 2.78,
"Odds2" : 3.9,
"Odds3" : 1.99,
"MaxBet" : 500,
"Bet" : "X12",
"BetGamePart" : 1,
"Line" : null,
"ID_IDENTITY" : 11
},
{
"id" : 62290843,
"BetId" : 2,
"BookieId" : 1,
"BookieBetId" : "14382217",
"ScrapingDateTime" : "2013-09-13T15:38:11.303",
"MinuteInGame" : null,
"GamePart" : null,
"Odds1" : 1.93,
"Odds2" : 1.95,
"Odds3" : null,
"MaxBet" : 1000,
"Bet" : "Total",
"BetGamePart" : 1,
"Line" : 0.75,
"ID_IDENTITY" : 12
},
{
"id" : 62381139,
"BetId" : 2,
"BookieId" : 1,
"BookieBetId" : "20864356",
"ScrapingDateTime" : "2013-09-13T15:38:11.303",
"MinuteInGame" : null,
"GamePart" : null,
"Odds1" : 2.05263,
"Odds2" : 1.85,
"Odds3" : null,
"MaxBet" : 2000,
"Bet" : "Total",
"BetGamePart" : 0,
"Line" : 2.0,
"ID_IDENTITY" : 13
},
{
"id" : 62381140,
"BetId" : 2,
"BookieId" : 1,
"BookieBetId" : "20864358",
"ScrapingDateTime" : "2013-09-13T15:38:11.303",
"MinuteInGame" : null,
"GamePart" : null,
"Odds1" : 2.15,
"Odds2" : 3.45,
"Odds3" : 3.1,
"MaxBet" : 1000,
"Bet" : "X12",
"BetGamePart" : 0,
"Line" : null,
"ID_IDENTITY" : 14
}
]
}
]
在400毫秒内获取0条记录 是我得到的,我做错了什么?
我试图在此字段上添加索引,索引已完成
答案 0 :(得分:1)
你的mongo查询应该是这样的:
db.testes.find({
'bets.DateTime': '2013-09-10T09:06:43.333'
}, {
'bets': {
$elemMatch: {
'DateTime': '2013-09-10T09:06:43.333'
}
}
})
或类似的东西:
db.testes.find({
'bets.DateTime': '2013-09-10T09:06:43.333'
}, {
'bets.$': 1
})
有用的链接: