如何在mongodb中查询日期?

时间:2018-03-26 03:39:16

标签: mongodb

我使用robo3T来测试我的查询命令。我的文档结构如下 enter image description here

我使用db.getCollection('Tainan').find({}, {"movie.film.releasedTime": 1}) 获取releasedTime

enter image description here

我尝试在18:00之后查询时间,所以我输入命令db.getCollection('Tainan').find({}, {"movie.film.releasedTime": {$gte: ISODate("2018-03-24T18:00:00.000Z")}})

我从robo3T收到错误

Error: error: {
    "ok" : 0,
    "errmsg" : "Unsupported projection option: movie.film.releasedTime: { $gte: new Date(1521914400000) }",
    "code" : 2,
    "codeName" : "BadValue"
}

不支持的投影选项?价值不好?

我错过了什么步骤?

任何帮助将不胜感激。提前谢谢。

这是我的文件json:

{
    "_id" : ObjectId("5ab8bb2ba2a6034a6d45044a"),
    "theater" : "Madou",
    "geometry" : {
        "type" : "Point",
        "coordinates" : [ 
            120.251206, 
            23.18388
        ]
    },
    "movie" : {
        "film" : {
            "moviePhoto" : [ 
                "https://movies.yahoo.com.tw/x/r/w420/i/o/production/movies/March2018/GD9otOLc6d3eprWHC1Ve-2757x4000.jpg", 
                "https://movies.yahoo.com.tw/x/r/w420/i/o/production/movies/March2018/MueV83b8cYC28yRbknIT-3254x4650.jpg"
            ],
            "movieStills" : [ 
                [ 
                    "https://movies.yahoo.com.tw/x/r/w340/i/o/production/movie-photos/October2017/lXva3RuipYTSXuWRJUNM-1000x414.JPG", 
                    "https://movies.yahoo.com.tw/x/r/w340/i/o/production/movie-photos/October2017/jZRNL98oLaVzfyQqNIL2-1000x419.JPG"
                ], 
                [ 
                    "https://movies.yahoo.com.tw/x/r/w340/i/o/production/movie-photos/October2017/N5peZRvbid7CTggnFobM-6345x4719.jpg", 
                    "https://movies.yahoo.com.tw/x/r/w340/i/o/production/movie-photos/October2017/QtBDIjaphADDrpmhbGAc-3198x2138.jpg"]
            ],
            "movieActorPhoto" : [ 
                [ 
                    "https://movies.yahoo.com.tw/x/r/h290/i/o/production/names/June2017/IEpk1o6Gn1Otyvv57yvj-1901x2853.jpg", 
                    "https://movies.yahoo.com.tw/x/r/w290/i/o/production/names/March2018/FPvy1nB8ec4pRULhfF6f-1000x667.JPG", 
                    "https://movies.yahoo.com.tw/x/r/h290/i/o/production/names/June2017/JKsyxkuicfEiOGKbwNcO-2286x3043.jpg"
                ], 
                [ 
                    "https://movies.yahoo.com.tw/x/r/h290/i/o/production/names/June2017/3NNkBmEMwAiV4Q7LoCaI-2189x3500.jpg"
                ]
            ],
            "movieActorCn" : [ 
                [ 
                    "史考特伊斯威特", 
                    "景甜", 
                    "菊地凜子"
                ], 
                [ 
                    "艾莉西亞薇坎德"
                ]
            ],
            "movieDate" : [ 
                "上映日期:2018-03-21", 
                "上映日期:2018-03-08"
            ],
            "versionType" : [ 
                "數位", 
                "數位"
            ],
            "videoId" : [ 
                [ 
                    "8BAhwgjMvnM", 
                    "_EhiLLOhVis"
                ], 
                [ 
                    "8ndhidEmUbI", 
                    "3KkhD0MnaJU"
                ]
            ],
            "imdbScore" : [ 
                "N/A", 
                "7.5"
            ],
            "cnName" : [ 
                "環太平洋2:起義時刻", 
                "古墓奇兵"
            ],
            "movieTime" : [ 
                "片  長:01時51分", 
                "片  長:01時58分"
            ],
            "movieContent" : [ 
                "test content"
            ],
            "movieStyle" : [ 
                [ 
                    "\n                    戰爭\n                  ", 
                    "\n                    動作\n                  ", 
                    "\n                    科幻\n                  "
                ], 
                [ 
                    "\n                    動作\n                  ", 
                    "\n                    冒險\n                  "
                ]
            ],
            "releasedTime" : [ 
                [ 
                    ISODate("2018-03-26T12:20:00.000Z"), 
                    ISODate("2018-03-26T14:30:00.000Z"), 
                    ISODate("2018-03-26T15:10:00.000Z"), 
                    ISODate("2018-03-26T16:40:00.000Z"), 
                    ISODate("2018-03-26T18:50:00.000Z"), 
                    ISODate("2018-03-26T21:00:00.000Z"), 
                    ISODate("2018-03-26T21:40:00.000Z")
                ], 
                [ 
                    ISODate("2018-03-26T13:00:00.000Z"), 
                    ISODate("2018-03-26T17:20:00.000Z"), 
                    ISODate("2018-03-26T19:30:00.000Z")
                ]
            ],
            "rottenScore" : [],
            "enName" : [ 
                "Pacific Rim Uprising", 
                "Tomb Raider"
            ]
        }
    },
    "phone" : "06-5722159",
    "address" : "testAddress",
    "theaterCn" : "testTheaterName"
}

我更新了文档结构:

{
    "_id" : ObjectId("5ab8c2bea2a6034e50c9a4f1"),
    "theater" : "Madou",
    "geometry" : {
        "type" : "Point",
        "coordinates" : [ 
            120.251206, 
            23.18388
        ]
    },
    "movie" : {
        "moviePhoto" : [ 
            "https://movies.yahoo.com.tw/x/r/w420/i/o/production/movies/March2018/GD9otOLc6d3eprWHC1Ve-2757x4000.jpg", 
            "https://movies.yahoo.com.tw/x/r/w420/i/o/production/movies/March2018/MueV83b8cYC28yRbknIT-3254x4650.jpg"
        ],
        "movieStills" : [ 
            [ 
                "https://movies.yahoo.com.tw/x/r/w340/i/o/production/movie-photos/October2017/lXva3RuipYTSXuWRJUNM-1000x414.JPG", 
                "https://movies.yahoo.com.tw/x/r/w340/i/o/production/movie-photos/October2017/jZRNL98oLaVzfyQqNIL2-1000x419.JPG"], 
            [ 
                "https://movies.yahoo.com.tw/x/r/w340/i/o/production/movie-photos/October2017/N5peZRvbid7CTggnFobM-6345x4719.jpg", 
                "https://movies.yahoo.com.tw/x/r/w340/i/o/production/movie-photos/October2017/QtBDIjaphADDrpmhbGAc-3198x2138.jpg"]
        ],
        "movieActorPhoto" : [ 
            [ 
                "https://movies.yahoo.com.tw/x/r/h290/i/o/production/names/June2017/IEpk1o6Gn1Otyvv57yvj-1901x2853.jpg", 
                "https://movies.yahoo.com.tw/x/r/w290/i/o/production/names/March2018/FPvy1nB8ec4pRULhfF6f-1000x667.JPG", 
                "https://movies.yahoo.com.tw/x/r/h290/i/o/production/names/June2017/JKsyxkuicfEiOGKbwNcO-2286x3043.jpg"
            ], 
            [ 
                "https://movies.yahoo.com.tw/x/r/h290/i/o/production/names/June2017/3NNkBmEMwAiV4Q7LoCaI-2189x3500.jpg"
            ]
        ],
        "movieActorCn" : [ 
            [ 
                "史考特伊斯威特", 
                "景甜", 
                "菊地凜子"
            ], 
            [ 
                "艾莉西亞薇坎德"
            ]
        ],
        "movieDate" : [ 
            "上映日期:2018-03-21", 
            "上映日期:2018-03-08"
        ],
        "versionType" : [ 
            "數位", 
            "數位"
        ],
        "videoId" : [ 
            [ 
                "8BAhwgjMvnM", 
                "_EhiLLOhVis"
            ], 
            [ 
                "8ndhidEmUbI", 
                "3KkhD0MnaJU"
            ]
        ],
        "imdbScore" : [ 
            "N/A", 
            "7.5"
        ],
        "cnName" : [ 
            "環太平洋2:起義時刻", 
            "古墓奇兵"
        ],
        "movieTime" : [ 
            "片  長:01時51分", 
            "片  長:01時58分"
        ],
        "movieContent" : [ 
            "testContent1        ", 
            "testContent2"
        ],
        "movieStyle" : [ 
            [ 
                "\n                    戰爭\n                  ", 
                "\n                    動作\n                  ", 
                "\n                    科幻\n                  "
            ], 
            [ 
                "\n                    動作\n                  ", 
                "\n                    冒險\n                  "
            ]
        ],
        "releasedTime" : [ 
            [ 
                ISODate("2018-03-26T12:20:00.000Z"), 
                ISODate("2018-03-26T14:30:00.000Z"), 
                ISODate("2018-03-26T15:10:00.000Z"), 
                ISODate("2018-03-26T16:40:00.000Z"), 
                ISODate("2018-03-26T18:50:00.000Z"), 
                ISODate("2018-03-26T21:00:00.000Z"), 
                ISODate("2018-03-26T21:40:00.000Z")
            ], 
            [ 
                ISODate("2018-03-26T13:00:00.000Z"), 
                ISODate("2018-03-26T17:20:00.000Z"), 
                ISODate("2018-03-26T19:30:00.000Z")
            ]
        ],
        "rottenScore" : [],
        "enName" : [ 
            "Pacific Rim Uprising", 
            "Tomb Raider"
        ]
    },
    "phone" : "06-5722159",
    "address" : "testAddress",
    "theaterCn" : "testTheaterName"
}

0 个答案:

没有答案