[{ "_id": { "$oid": "5d7a76c94c3c8c05618cef58" }, "title": "hello", "date": { "$date": "2019-06-07T07:22:00.000Z" }, "__v": 0}, { "_id": { "$oid": "5d7a7809ef31980615ed3756" }, "title": "hello", "date": { "$date": "2019-06-08T07:22:00.000Z" }, "__v": 0}, { "_id": { "$oid": "5d7a78e712c75706a3fdb025" }, "title": "hello6", "date": { "$date": "2019-07-19T08:22:00.000Z" }, "__v": 0}, { "_id": { "$oid": "5d7a78e712c75706a3fdb025" }, "title": "hello7", "date": { "$date": "2019-07-03T08:22:00.000Z" }, "__v": 0}]我正在使用 mongoose 将我的数据存储在 mongodb 中,我正在尝试使用 mongoose我想要从日期2019-07-01到的所有文档。2019-07-31我们可以在 mongoDB 中对 mongoose 执行此过滤器吗预期产出[{ "_id": { "$oid": "5d7a78e712c75706a3fdb025" }, "title": "hello6", "date": { "$date": "2019-07-19T08:22:00.000Z" }, "__v": 0}, { "_id": { "$oid": "5d7a78e712c75706a3fdb025" }, "title": "hello7", "date": { "$date": "2019-07-03T08:22:00.000Z" }, "__v": 0}]这是我的代码 https://codesandbox.io/s/lively-tree-hd0foapp.get("/saveData", async () => { try { var blog = new BlogPostModel({ title: "hello6", date: "19-Jul-2019 08:22" }); console.log("before save"); let saveBlog = await blog.save(); //when fail its goes to catch console.log(saveBlog); //when success it print. console.log("saveBlog save"); } catch (error) { console.log(error); }});
1 回答
桃花长相依
TA贡献1860条经验 获得超8个赞
您可以使用 MongoDB 的$gte
(大于或等于)和$lte
(小于或等于):
blog.find({ date: { $gte: '2019-07-01', $lte: '2019-07-31' } });
添加回答
举报
0/150
提交
取消