2016-12-11 1 views
0

가격을 쿼리하는 방법을 알아내는 데 어려움을 겪고 있습니다. 현재 시도가 작동하지 않고 로컬 호스트에 입력해야 할 항목이 확실치 않습니다.노드 js express - 가격 필드를 쿼리

http://localhost:3000/priceSearch?

내가 구현 한 - orderSearch.find ({가격 : {$에있다 : 400, $의 LT : 700}})

내 MongoDB의에서 가격 필드에 숫자가 아닌

감사합니다 aa는 문자열입니다 : 여기

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; 

답변

0
req.query.price; 

나는 바보 같은 것을 추가했습니다.

관련 문제