node.js - How can I check given date is between two dates in mongodb? -


{   "_id": {     "$oid": "asdf976"   },   "categories": [{     "mainmodels": [{       "submodels": [{           "price": "2000",           "submodelname": "lumia021",          }, {           "price": "2000",           "submodelname": "lumia341",          }        ],       "status": "active",       "modelname": "lumia",       "fromdate": "15/04/2016",       "todate": "29/04/2016"     }],     "brand": "nokia"   }],   "rank": "1",   "name": "first mobile station" }  {   "_id": {     "$oid": "asdf976"   },   "categories": [{     "mainmodels": [{       "submodels": [{           "price": "2000",           "submodelname": "lumia a02",          }, {           "price": "2000",           "submodelname": "lumia trend",          }        ],       "status": "active",       "modelname": "lumia",       "fromdate": "20/04/2016",       "todate": "21/04/2016"     }],     "brand": "nokia"   }],   "rank": "2",   "name": "zahid station" } {   "_id": {     "$oid": "asdf976"   },   "categories": [{     "mainmodels": [{       "submodels": [{           "price": "2000",           "submodelname": "trend 45",          }, {           "price": "2000",           "submodelname": "trendz",          }        ],       "status": "active",       "modelname": "trend",       "fromdate": "10/04/2016",       "todate": "21/04/2016"     }],     "brand": "samsung"   }],   "rank": "3",   "name": "mobi cell station"  } 

above have added data's stored in mongodb database . how can find data ever "status": "active", "modelname": "lumia", "date":"19/04/2016"

above condtion date thing can't able solve here given date between fromdate , todate should give result

i need check given date (19/04/2016) between fromdate , todate after need check "status": "active", "modelname": "lumia",

my controller:

exports.search = function(req, res) {  var condition = { 'modelname': 'lumia', 'status':'active'   };         phone.find(condition).sort('-created').populate('user', 'displayname').exec(function(err, phones) {                 if (err) {                         return res.status(400).send({                                 message: errorhandler.geterrormessage(err)                         });                 } else {                         res.jsonp(phones);                  }         }); }; 

schema:

var mongoose = require('mongoose'),     schema = mongoose.schema;  var submodelschema = {    submodelname: {type:string, required: false},    price: {type:string, required: false},    remainingphones: {type:string, required: false},    bookedphones: {type:string, required: false},    numofphones: {type:string, required: false}  };  submodelschema  = 'new schema('+ submodeleschema +',{_id:true})';  var typeschema = {    vtype: {type:string, required: false},    mainservices: {    status: {type:string, required: false},    modelname : {type:string, required: false},    fromdate: {type: date,default: date.now},    todate: {type: date,default: date.now}    },    submodels: [submodelschema], default:[] }; typeschema  = 'new schema('+typeschema +',{_id:true})';  var phoneschema = new schema({         rank: {                 type: string,                 default: '',                 trim: true         },         name: {                 type: string,                 default: '',                 trim: true         },    categories: [typeschema], default:[]   });  mongoose.model('phone', phoneschema); 

i didn't understand question should store date date. , can design schema this

    fromdate: date,     untildate: date 

and find if date falls between dates stored in fromdate , untildate can use $gte , $lt

 $gte: fromdate,  $lte : untildate 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -