【问题标题】:MongoDB lte doesn't workMongoDB lte 不工作
【发布时间】:2015-04-24 20:43:23
【问题描述】:

您好,我正在尝试植入 mongodb lte 功能 http://docs.mongodb.org/manual/reference/operator/query/lte/

但它似乎不起作用:s 我的路线:

app.route('/sign/:projectId/:startWeek/:endWeek')
    .post(sign.readExport);

控制器:

exports.readExport = function(req, res) {
    Sign.find()
        .where('projectId').equals(req.params.projectId)
        .where('startWeek').gte(req.params.startWeek).lte(req.params.endWeek)
        .sort('-created')
        .exec(function(err, sign) {
            if (err) {
                return res.status(400).send({
                    message: errorHandler.getErrorMessage(err)
                });
            } else {
                res.jsonp(sign);
            }
        });
};

得到一个带有 startWeek":"9" 的 db 对象

使用邮递员我得到这些结果

http://localhost:3000/sign/658/8/8
//respons null as it should

http://localhost:3000/sign/658/8/9
//respons my object as it should

http://localhost:3000/sign/658/8/10
http://localhost:3000/sign/658/8/11
http://localhost:3000/sign/658/8/12...
//respons null should respons my object ??

我做错了什么? :)

【问题讨论】:

  • @JohnnyHK 是的。让它现在工作!刚刚将 db 值从字符串更改为数字 thx:p 您可以将其发布为答案 :)

标签: javascript mongodb rest express mongoose


【解决方案1】:

数字字符串的排序让你大吃一惊。您需要将文档中的 startWeek 值更改为数字而不是字符串。

'10' < '9',但10 > 9

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-12
    • 1970-01-01
    • 2016-11-17
    • 2015-11-18
    • 2014-09-17
    • 2015-05-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多