MongoDB如何在嵌套数组上搜索文档



嗨,我是MongoDB的新手,并试图对我创建的集合执行查询,该集合看起来像这样:

{ 
"_id" : ObjectId("574c55312368e5aa90bbf27b"), 
"id" : NumberInt(10000), 
"BookieId" : NumberInt(1), 
"EventBookieId" : null, 
"LeagueId" : NumberInt(214), 
"LeagueNameId" : NumberInt(4571), 
"Team1Id" : NumberInt(435), 
"Team1NameId" : null, 
"Team2Id" : NumberInt(430), 
"Team2NameId" : null, 
"EventDateTime" : ISODate("2013-09-14T13:00:00.000+0000"), 
"isNew" : true, 
"CountryId" : NumberInt(36), 
"isCountry" : true, 
"isLeague" : true, 
"Gameid" : null, 
"Reversed" : false, 
"eventId" : NumberInt(10000), 
"bets" : [
    {
        "id" : NumberInt(1), 
        "EventConnectionId" : NumberInt(10000), 
        "isCorners" : false, 
        "DateTime" : ISODate("2013-09-10T08:06:43.333+0000"), 
        "IsLive" : false, 
        "Team1Score" : null, 
        "Team2Score" : null, 
        "Team1RedCards" : null, 
        "Team2RedCards" : null, 
        "odds" : [
        ]
    }, 
    {
        "id" : NumberInt(2), 
        "EventConnectionId" : NumberInt(10000), 
        "isCorners" : false, 
        "DateTime" : ISODate("2013-09-10T18:50:26.840+0000"), 
        "IsLive" : false, 
        "Team1Score" : NumberInt(0), 
        "Team2Score" : NumberInt(0), 
        "Team1RedCards" : null, 
        "Team2RedCards" : null, 
        "odds" : [
            {
                "id" : NumberInt(62282718), 
                "BetId" : NumberInt(2), 
                "BookieId" : NumberInt(1), 
                "BookieBetId" : "21968173", 
                "ScrapingDateTime" : ISODate("2013-09-13T07:39:15.810+0000"), 
                "MinuteInGame" : null, 
                "GamePart" : null, 
                "Odds1" : 1.81, 
                "Odds2" : 2.1236, 
                "Odds3" : null, 
                "MaxBet" : NumberInt(2000), 
                "Bet" : "Hcap", 
                "BetGamePart" : NumberInt(0), 
                "Line" : -0.25, 
                "ID_IDENTITY" : NumberInt(1)
            }, 
            {
                "id" : NumberInt(62282719), 
                "BetId" : NumberInt(2), 
                "BookieId" : NumberInt(1), 
                "BookieBetId" : "21968175", 
                "ScrapingDateTime" : ISODate("2013-09-13T07:39:15.810+0000"), 
                "MinuteInGame" : null, 
                "GamePart" : null, 
                "Odds1" : 2.04167, 
                "Odds2" : 1.86, 
                "Odds3" : null, 
                "MaxBet" : NumberInt(2000), 
                "Bet" : "Total", 
                "BetGamePart" : NumberInt(0), 
                "Line" : 2.0, 
                "ID_IDENTITY" : NumberInt(2)
            }, 
            {
                "id" : NumberInt(62282720), 
                "BetId" : NumberInt(2), 
                "BookieId" : NumberInt(1), 
                "BookieBetId" : "21968177", 
                "ScrapingDateTime" : ISODate("2013-09-13T07:39:15.810+0000"), 
                "MinuteInGame" : null, 
                "GamePart" : null, 
                "Odds1" : 2.16, 
                "Odds2" : 3.45, 
                "Odds3" : 3.05, 
                "MaxBet" : NumberInt(1000), 
                "Bet" : "X12", 
                "BetGamePart" : NumberInt(0), 
                "Line" : null, 
                "ID_IDENTITY" : NumberInt(3)
            }, 
            {
                "id" : NumberInt(62282721), 
                "BetId" : NumberInt(2), 
                "BookieId" : NumberInt(1), 
                "BookieBetId" : "21968179", 
                "ScrapingDateTime" : ISODate("2013-09-13T07:39:15.810+0000"), 
                "MinuteInGame" : null, 
                "GamePart" : null, 
                "Odds1" : 2.21951, 
                "Odds2" : 1.7, 
                "Odds3" : null, 
                "MaxBet" : NumberInt(1000), 
                "Bet" : "Hcap", 
                "BetGamePart" : NumberInt(1), 
                "Line" : -0.25, 
                "ID_IDENTITY" : NumberInt(4)
            }, 
            {
                "id" : NumberInt(62282722), 
                "BetId" : NumberInt(2), 
                "BookieId" : NumberInt(1), 
                "BookieBetId" : "21968180", 
                "ScrapingDateTime" : ISODate("2013-09-13T07:39:15.810+0000"), 
                "MinuteInGame" : null, 
                "GamePart" : null, 
                "Odds1" : 2.78, 
                "Odds2" : 3.9, 
                "Odds3" : 1.99, 
                "MaxBet" : NumberInt(500), 
                "Bet" : "X12", 
                "BetGamePart" : NumberInt(1), 
                "Line" : null, 
                "ID_IDENTITY" : NumberInt(5)
            }, 
            {
                "id" : NumberInt(62282723), 
                "BetId" : NumberInt(2), 
                "BookieId" : NumberInt(1), 
                "BookieBetId" : "21968181", 
                "ScrapingDateTime" : ISODate("2013-09-13T07:39:15.810+0000"), 
                "MinuteInGame" : null, 
                "GamePart" : null, 
                "Odds1" : 1.93, 
                "Odds2" : 1.95, 
                "Odds3" : null, 
                "MaxBet" : NumberInt(1000), 
                "Bet" : "Total", 
                "BetGamePart" : NumberInt(1), 
                "Line" : 0.75, 
                "ID_IDENTITY" : NumberInt(6)
            }, 
            {
                "id" : NumberInt(62290838), 
                "BetId" : NumberInt(2), 
                "BookieId" : NumberInt(1), 
                "BookieBetId" : "14382209", 
                "ScrapingDateTime" : ISODate("2013-09-13T14:38:11.303+0000"), 
                "MinuteInGame" : null, 
                "GamePart" : null, 
                "Odds1" : 1.81, 
                "Odds2" : 2.1236, 
                "Odds3" : null, 
                "MaxBet" : NumberInt(2000), 
                "Bet" : "Hcap", 
                "BetGamePart" : NumberInt(0), 
                "Line" : -0.25, 
                "ID_IDENTITY" : NumberInt(7)
            }, 
            {
                "id" : NumberInt(62290839), 
                "BetId" : NumberInt(2), 
                "BookieId" : NumberInt(1), 
                "BookieBetId" : "14382211", 
                "ScrapingDateTime" : ISODate("2013-09-13T08:27:39.600+0000"), 
                "MinuteInGame" : null, 
                "GamePart" : null, 
                "Odds1" : 2.05263, 
                "Odds2" : 1.85, 
                "Odds3" : null, 
                "MaxBet" : NumberInt(2000), 
                "Bet" : "Total", 
                "BetGamePart" : NumberInt(0), 
                "Line" : 2.0, 
                "ID_IDENTITY" : NumberInt(8)
            }, 
            {
                "id" : NumberInt(62290840), 
                "BetId" : NumberInt(2), 
                "BookieId" : NumberInt(1), 
                "BookieBetId" : "14382213", 
                "ScrapingDateTime" : ISODate("2013-09-13T09:29:22.863+0000"), 
                "MinuteInGame" : null, 
                "GamePart" : null, 
                "Odds1" : 2.15, 
                "Odds2" : 3.45, 
                "Odds3" : 3.1, 
                "MaxBet" : NumberInt(1000), 
                "Bet" : "X12", 
                "BetGamePart" : NumberInt(0), 
                "Line" : null, 
                "ID_IDENTITY" : NumberInt(9)
            }, 
            {
                "id" : NumberInt(62290841), 
                "BetId" : NumberInt(2), 
                "BookieId" : NumberInt(1), 
                "BookieBetId" : "14382215", 
                "**ScrapingDateTime" : ISODate**("2013-09-13T14:38:11.303+0000"), 
                "MinuteInGame" : null, 
                "GamePart" : null, 
                "Odds1" : 2.21951, 
                "Odds2" : 1.7, 
                "Odds3" : null, 
                "MaxBet" : NumberInt(1000), 
                "Bet" : "Hcap", 
                "BetGamePart" : NumberInt(1), 
                "Line" : -0.25, 
                "ID_IDENTITY" : NumberInt(10)
            }, 
            {
                "id" : NumberInt(62290842), 
                "BetId" : NumberInt(2), 
                "BookieId" : NumberInt(1), 
                "BookieBetId" : "14382216", 
                "ScrapingDateTime" : ISODate("2013-09-13T14:38:11.303+0000"), 
                "MinuteInGame" : null, 
                "GamePart" : null, 
                "Odds1" : 2.78, 
                "Odds2" : 3.9, 
                "Odds3" : 1.99, 
                "MaxBet" : NumberInt(500), 
                "Bet" : "X12", 
                "BetGamePart" : NumberInt(1), 
                "Line" : null, 
                "ID_IDENTITY" : NumberInt(11)
            }, 
            {
                "id" : NumberInt(62290843), 
                "BetId" : NumberInt(2), 
                "BookieId" : NumberInt(1), 
                "BookieBetId" : "14382217", 
                "ScrapingDateTime" : ISODate("2013-09-13T14:38:11.303+0000"), 
                "MinuteInGame" : null, 
                "GamePart" : null, 
                "Odds1" : 1.93, 
                "Odds2" : 1.95, 
                "Odds3" : null, 
                "MaxBet" : NumberInt(1000), 
                "Bet" : "Total", 
                "BetGamePart" : NumberInt(1), 
                "Line" : 0.75, 
                "ID_IDENTITY" : NumberInt(12)
            }, 
            {
                "id" : NumberInt(62381139), 
                "BetId" : NumberInt(2), 
                "BookieId" : NumberInt(1), 
                "BookieBetId" : "20864356", 
                "ScrapingDateTime" : ISODate("2013-09-13T14:38:11.303+0000"), 
                "MinuteInGame" : null, 
                "GamePart" : null, 
                "Odds1" : 2.05263, 
                "Odds2" : 1.85, 
                "Odds3" : null, 
                "MaxBet" : NumberInt(2000), 
                "Bet" : "Total", 
                "BetGamePart" : NumberInt(0), 
                "Line" : 2.0, 
                "ID_IDENTITY" : NumberInt(13)
            }, 
            {
                "id" : NumberInt(62381140), 
                "BetId" : NumberInt(2), 
                "BookieId" : NumberInt(1), 
                "BookieBetId" : "20864358", 
                "ScrapingDateTime" : ISODate("2013-09-13T14:38:11.303+0000"), 
                "MinuteInGame" : null, 
                "GamePart" : null, 
                "Odds1" : 2.15, 
                "Odds2" : 3.45, 
                "Odds3" : 3.1, 
                "MaxBet" : NumberInt(1000), 
                "Bet" : "X12", 
                "BetGamePart" : NumberInt(0), 
                "Line" : null, 
                "ID_IDENTITY" : NumberInt(14)
            }
        ]
    }
]

和我想要得到所有的"赔率"。日期之间的ScrapingDateTime,不明白怎么做,有人可以帮助吗?

这可能对你有帮助。

 db.test.find({'bets.odds.ScrapingDateTime':{'$gte':ISODate("2013-09-13T14:38:11.303Z"),
'$lt':ISODate("2013-09-14T14:38:11.303Z")}},{"bets.odds.ScrapingDateTime":1,_id:0}).pretty()

相关内容

  • 没有找到相关文章

最新更新