【问题标题】:node js express - querying the price fieldnode js express - 查询价格字段
【发布时间】:2016-12-11 22:45:55
【问题描述】:

我不知道如何查询价格。我目前的尝试不起作用,我不确定您必须在本地主机中输入什么。

http://localhost:3000/priceSearch?

我已经实现了 - orderSearch.find({price:{$gt:400, $lt: 700}})

我的 mongodb 中的价格字段是数字而不是字符串

谢谢你:D

这是我的代码:

priceSearch.ejs

var express = require('express');
var router = express.Router();
var mongodb = require('mongodb');
var MongoClient = mongodb.MongoClient;
var url = 'mongodb://localhost:27017/WishList';


router.get('/', function (req, res) {
    var price = req.query.price;

    MongoClient.connect(url, function (err, db) {
        if (err) {
            console.log("Unable to connect to the server", err);
        } else {
            console.log("Connection established...");
            var orderSearch = db.collection('orders');

            // find document who satisify price
            orderSearch.find({price:{$gt:400, $lt: 700}}).toArray(function (err, result) {
                if (err) {
                    res.send(err);
                } else if (result.length) {
                    res.render('priceSearch',
                        {
                            priceSearch: result,
                            title: 'Product price search',
                        }
                    );
                } else {
                    res.send("No documents found");
                }

                db.close();
            });
        }

    });
});

module.exports = router;

【问题讨论】:

    标签: javascript node.js express ejs


    【解决方案1】:
    req.query.price;
    

    我添加了一个愚蠢的变量

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-18
      • 2013-02-01
      • 2017-07-31
      相关资源
      最近更新 更多