【发布时间】:2014-06-11 13:08:28
【问题描述】:
好的,所以我在使用 mongodb 时遇到了困难,来自 MySQL 我遇到了麻烦 编写查询以获取我的数据。我的数据库如下所示:
opened: [
{day: "Monday", from: 64800, till: 79200},
{day: "Thuesday", from: 64800, till: 79200},
{day: "Wednesday", from: 64800, till: 79200},
{day: "Thursday", from: 64800, till: 79200},
{day: "Friday", from: 64800, till: 79200},
{day: "Saturday", from: 64800, till: 79200},
{day: "Sunday", from: 64800, till: 79200}
]
我想要完成的是以下内容: 我有一个名为:currendTime 的变量,我有一个变量,其中我将 currentDay 作为全名。所以变量 currentDay 包含“Friday”。
我想要实现的是搜索currentDay等于Friday并且当前时间高于“from”并且currentTime低于“till”的那一天
有人可以帮我吗?
更新 这是我目前所拥有的:
db.collection('test', function(err, collection) {
collection.find(
{
opened: {$and: [{$elemMatch: {day: weekDay}},
{from: {$lt: currentTime}},
{till: {$gt: currentTime}}]}
}).toArray(function(err,items) {
res.send(items);
});
【问题讨论】:
-
您是否查看过有关将 SQL 概念转换为 MongoDB 的文档? docs.mongodb.org/manual/reference/sql-comparison/#select
-
我有,这就是我想出的:**检查上面**但是它什么也没返回:(**我会在上面添加代码^^ **
标签: mysql node.js mongodb mongoose mongodb-query