{
"_id" : ObjectId("5d3180f90bf69d240419b1aa"),
"marketName" : "安德鲁炸鸡汉堡",
"marketTimes" : [
{
"_id" : NumberLong(1029),
"time_open" : "09:00:00",
"time_over" : "22:00:00",
}
]
}
/* 2 */
{
"_id" : ObjectId("5d3180f90bf69d240419b1ab"),
"marketName" : "关爱食尚快餐",
"marketTimes" : [
{
"_id" : NumberLong(1030),
"time_open" : "09:00:00",
"time_over" : "15:00:00",
},
{
"_id" : NumberLong(1031),
"time_open" : "17:00:00",
"time_over" : "22:00:00",
}
]
}
db.demo147.find({ 'Details.Score': { $gt: 45, $lt: 50 }});
mongodb时间的用的比较少,不过比较用的多,你可以试下
https://www.mongodb.com/docs/
聚合一下,做时间查询,或者感觉你这个格式可以变成int直接对比就行了
目前的时间使用字符串,比较起来会有问题,建议转为时间戳。
db.products.insertMany( [
{
"_id" : ObjectId("5d3180f90bf69d240419b1aa"),
"marketName" : "安德鲁炸鸡汉堡",
"marketTimes" : [
{
"_id" : NumberLong(1029),
"time_open" : "09:00:00",
"time_over" : "22:00:00",
}
]
},
{
"_id" : ObjectId("5d3180f90bf69d240419b1ab"),
"marketName" : "关爱食尚快餐",
"marketTimes" : [
{
"_id" : NumberLong(1030),
"time_open" : "09:00:00",
"time_over" : "15:00:00",
},
{
"_id" : NumberLong(1031),
"time_open" : "17:00:00",
"time_over" : "22:00:00",
}
]
},
] );
> db.products.find({"marketTimes.time_open" : {"$lte" : "15:30:00"}, "marketTimes.time_over" : {"$gte" : "15:30:00"}}, {marketTimes:1})
{ "_id" : ObjectId("5d3180f90bf69d240419b1aa"), "marketTimes" : [ { "_id" : NumberLong(1029), "time_open" : "09:00:00", "time_over" : "22:00:00" } ] }
{ "_id" : ObjectId("5d3180f90bf69d240419b1ab"), "marketTimes" : [ { "_id" : NumberLong(1030), "time_open" : "09:00:00", "time_over" : "15:00:00" }, { "_id" : NumberLong(1031), "time_open" : "17:00:00", "time_over" : "22:00:00" } ] }