简体   繁体   中英

Querying in mongodb using mongoose

I have a schema in the below format:

var ServiceSchema = new Schema({ createdAt:Date,name:String,ExpiryDate:Date});

I need to query the database comparing the createdAt and expiryDate and get the results.

Say i need to query the values where createdDate>ExpiryDate .

Any idea as how to write the query using mongoose will be really helpful.

The following code snippet should work.

ServiceSchema.find( {$where: 'this.createdDate > this.ExpiryDate'}, 
   function(err, results) { 
     ///
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM