웹 서버에서 Node.js와 Express를 사용하여 dbserver에서 MongoDB를 쿼리하고 함께 작동하는 데 문제가 발생하면 여기 문제에 대한 스레드의 무리, 특히이 하나Node.js, Express 및 MongoDB를 사용하여 ISODate로 찾기
Inserting and Querying Date with MongoDB and Nodejs
나는 내가이 일을하기로되어있어 이해 확신 해요,하지만 난 시도 아무것도 작동하는 것 같다 없습니다. 내의 .js 파일에서
, 나는 다음과 같은 한 : 콘솔에
var todayStart = new Date();
todayStart.setSeconds(0);
todayStart.setHours(0);
todayStart.setMinutes(0);
todayStart.setMilliseconds(0);
var todayEnd = new Date(todayStart);
todayEnd.setHours(23);
todayEnd.setMinutes(59);
todayEnd.setSeconds(59);
todayEnd.setMilliseconds(999);
var query = {
"date": {
$gte: new Date(todayStart).toISOString(),
$lte: new Date(todayEnd).toISOString()
}
};
내 쿼리 VAR 출력을 형식으로 내가 기대 :
{ date:
{ '$gte': '2016-09-13T00:00:00.000Z',
'$lte': '2016-09-13T23:59:59.999Z' }
}
가 나도 내 쿼리 변수를 사용하려고 또는 날짜 자신을 바르, 모두가 null의 결과 (오류없이) 반환 : 그러나
db.collection('test').findOne(query, function(err, result) {
db.collection('test').findOne({"date" : {$gte: new Date(todayStart).toISOString(),$lte: new Date(todayEnd).toISOString() }}, function(err, result) {
을 그냥 페이지의 경우 내 날짜의 러그는 그렇듯이 내 결과를 반환합니다.
db.collection('test').findOne({"date" : {$gte: new Date("2016-09-13T00:00:00.000Z"),$lte: new Date("2016-09-13T23:59:59.999Z") }}, function(err, result) {
내가 여기에없는 것이 있습니까?
감사합니다 톤. 나는 그것을 분명히 지나치게 복잡하게 만들고 있었다. 매력처럼 일했습니다. –
@NickSchroeder 걱정하지 않아도됩니다. – chridam