lwd219
V2EX  ›  问与答

mongoose 如何返回特定时间段数据

  •  
  •   lwd219 · Mar 26, 2019 · 918 views
    This topic created in 2622 days ago, the information mentioned may be changed or developed.

    假定数据结构如下:

    {
        userid:1111,
        data1:[
            {title:'test',content:'test',createTime:'2019-03-25T09:24:00.000Z'}
            {title:'test',content:'test',createTime:'2019-03-25T09:24:00.000Z'}
        ]
    },
    {
        userid:2222,
        data1:[
            {title:'test',content:'test',createTime:'2019-03-25T09:24:00.000Z'}
            {title:'test',content:'test',createTime:'2019-03-25T09:24:00.000Z'}
        ]
    }
    

    我执行了如下代码但是返回了所有时间段的数据,并不能达到要求

    const start = new Date(2019,3,1)
    const end = new Date(2019,3,31)
    schema.find({userId:req.body.userId,"data1.createTime":{$gte: start,$lt: end}})
    

    小白求助下

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2774 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 46ms · UTC 10:05 · PVG 18:05 · LAX 03:05 · JFK 06:05
    ♥ Do have faith in what you're doing.