Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6747207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:24:52+00:00 2026-05-26T12:24:52+00:00

I have a collection with documents that have a start_time and end_time property. the

  • 0

I have a collection with documents that have a start_time and end_time property. the strucute of the document is as follows:

{
_id     "4e9650ed1d41c811bc000000"
bid     31.0
start_time  2011-04-04 09:30:00 UTC
volume  31.0
end_time    2011-04-04 09:59:59 UTC
ask     0.0
price   1329.75
}

I want to be able to pull apart the date fields into date and time components and query on each seperately. An example query would be:

Get me all documents that are between (9:00 and 9:30) and between (2011-04-04 and 2011-05-04)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:24:53+00:00Added an answer on May 26, 2026 at 12:24 pm

    If space is not an issue to store additional denormalized fields and you are at the design part of the application (so you don’t have to come back and modify existing data), you could:

    • Store the start-hour and end-hour as additional attributes to keep the hour/minutes.
    • Apply composite indices on start_time, start_hour and end_time, end_hour so your search performance is good.
    • Run a query on all four fields.

    See sample document:

    { 
      _id: "4e9650ed1d41c811bc000000", 
      bid: 31.0,
      start_time: 2011-04-04 09:30:00 UTC,
      start_hour: "09:30:00",  // new field
      volume: 31.0,
      end_time: 2011-04-04 09:59:59 UTC,
      end_hour: "09:59:59",    // new field
      ask: 0.0 ,
      price 1329.75 
    }
    

    It seems that the answer to your questions is that you cannot separate the components of the date and time efficiently in your query and for example take advantage of indices to speed up queries.

    My suggestion above requires changing your schema slightly to achieve what you need. It seems that it would pay off greatly for the sacrifice of a few bytes extra on each document and the minor code changes.

    If you have existing data, you could run a Map/Reduce to separate the components into a new collection and use that new collection going forward.

    I hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am beginning with mongodb and have a collection with documents that look like
In MongoDB I have a collection of documents called 'clients', where each document is
I have a collection of documents that I'm attempting to parse. Like HTML, they
I currently have a collection of documents that each contain arrays pointing at other
I have a MongoDB collection with documents in the following format: { _id :
for example I have collection foo of documents like that: {tag_cloud:[{value:games, count:10}, {value:girls, count:500}]}
I have a collection of HTML documents for which I need to parse the
I have a large collection of documents scanned into PDF format, and I wish
I have a collection of classes that inherit from an abstract class I created.
I have a collection of non-overlapping rectangles that cover an enclosing rectangle. What is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.