javascript - How do I use a Date object in a Mongoose findOne() call -


i have schema date element:

var = new mongoose.schema({ name : string, date : date, }); 

i working data stores date in format 2005-08-13

when insert data, goes in fine. query in mongo console, , there date (with hours set 12:00 etc, fine).

the problem is, node.js, when try lookup:

models('meetings').findone({ name: result.meeting.$.name }, { date: result.meeting.$.date }, function (err, meeting) { 

the date criteria returns true - i.e. matches no matter what. in particular thinks "2008-04-06" match "2008-04-21".

any ideas?

you're not including date in query conditions because you're passing findone field selection object (second parameter). you're querying name.

put both query conditions single object:

models('meetings').findone(     { name: result.meeting.$.name, date: result.meeting.$.date },      function (err, meeting) { ... 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -