Amanda G
Amanda G

Reputation: 1981

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.

Upvotes: 0

Views: 65

Answers (1)

idursun
idursun

Reputation: 6335

The following code snippet should work.

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

Upvotes: 1

Related Questions