Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

52
Views
Query by date string in MongoDB?

I have a string field in a collection which stores date in this format 3 Mar 2022. Is there anyway to apply $gt and $lt operators on this in the query? Or is there any other way to query this field? I am using nodejs/mongoose for querying. Schema sample

export const SampleSchema = new EntitySchema(
    {
        startValidity: { type: String },
        endValidity: { type: String },
    },
    { collection: 'Sample'},
)

Please help.

7 months ago · Juan Pablo Isaza
1 answers
Answer question

0

if your date field is of type date, then you can query like

{ $and: [{ myDateField: { $gte: myDateQuery1} }, { myDateField: { $lte: myDateQuery1} }] }
7 months ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.