0

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.

Ionică Bizău
114k95 gold badges311 silver badges489 bronze badges
asked Feb 7, 2013 at 9:27

1 Answer 1

1

The following code snippet should work.

ServiceSchema.find( {$where: 'this.createdDate > this.ExpiryDate'}, 
 function(err, results) { 
 ///
});
answered Feb 7, 2013 at 9:37
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks will try and let u know :)

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.