我正在使用 mongodb 版本4.2.2
。
我有以下数据:
{
"_id" : ObjectId("5f0c58089c058304f7a64fa9"),
"date" : ISODate("2021-07-11T00:00:00.000Z"),
"dayOfWeek" : 0,
"staffMember" : ObjectId("5f0c58076b559419d62efe47"),
"startTime" : 885
},
/* 2 createdAt:2020-07-13T12:48:08.000Z*/
{
"_id" : ObjectId("5f0c58089c058304f7a64fa8"),
"date" : ISODate("2021-07-11T00:00:00.000Z"),
"dayOfWeek" : 0,
"staffMember" : ObjectId("5f0c58076b559419d62efe47"),
"startTime" : 870
},
/* 3 createdAt:2020-07-13T12:48:08.000Z*/
{
"_id" : ObjectId("5f0c58089c058304f7a64fa7"),
"date" : ISODate("2021-07-11T00:00:00.000Z"),
"dayOfWeek" : 0,
"staffMember" : ObjectId("5f0c58076b559419d62efe47"),
"startTime" : 855
},
/* 4 createdAt:2020-07-13T12:48:08.000Z*/
{
"_id" : ObjectId("5f0c58089c058304f7a64fa6"),
"date" : ISODate("2021-07-11T00:00:00.000Z"),
"dayOfWeek" : 0,
"staffMember" : ObjectId("5f0c58076b559419d62efe47"),
"startTime" : 840
}
我mongoose
在我的项目中使用。当我在节点 js 中运行此查询时:
const { memberId, date } = req.params;
let isoDate = date.toISOString();
let timeSlots = await TimeSlots.find(
{
staffMember: memberId,
date: isoDate
});
结果打印在console
:
db.spaTimeSlots.find({"staffMember" : ObjectId("5f0c58076b559419d62efe47"), date: new Date("Wed, 11 Jul 2020 00:00:00 GMT")})
.projection({})
.sort({_id:-1})
.limit(100)
但是,我想要这个结果:
db.spaTimeSlots.find({"staffMember" : ObjectId("5f0c58076b559419d62efe47"), date: ISODate("2021-07-11T00:00:00.000Z")})
.projection({})
.sort({_id:-1})
.limit(100)
我希望以ISODate
格式返回的结果,而不是文本(即不是Wed, 11 Jul
)。