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 8947571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:47:50+00:00 2026-06-15T12:47:50+00:00

I have a mongo store task, that has an array answers, which takes a

  • 0

I have a mongo store “task”, that has an array “answers”, which takes a hash, on of whose elements is a timestamp. So:

task ->
  project_id,
  answers ->
    [ 
       {
         timestamp: <time>,
         question_1: <answer_1>,
         question_2: <answer_2>
       },
       {
         timestamp: <time>,
         question_1: <answer_1>,
         question_2: <answer_2>
       },
    ]

What I’d like to do is get a list of all tasks that have a given project ID, and whose latest answer timestamp field falls within the past 24h. The project ID thing is obviously pretty straightforward, and I can determine if a timestamp falls between the given period with $gte and $lt…but I don’t know how to scope that to the latest timestamp only.

I’m not using an ORM for this – so just the plain mongo query syntax preferred.

Any advice appreciated.

  • 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-06-15T12:47:51+00:00Added an answer on June 15, 2026 at 12:47 pm

    Map Reduce, as @shelman, mentioned is not required and I would not consider it the best method here. Note that MR is not really designed to run inline to your own application and is slow (by definition).

    You would typically be better off with either the aggregation framework (which can easily do this) or better yet a normal query.

    Now even though you want to know if the latest projects answers falls within 24 hours it is probably a good bet to assume that any project answer that falls within the 24 hour period should be included since that most likely means the latest does (if not then why not?). So this can be achieved with (again as @shelman said):

    find({project_id: 5, "answers.timestamp": {$gte: ISODate(), $lt: ISODate()}})
    

    That will find any project with answers within the last 24 hours. You cna then filter out the first/last answer (which should always be the one your looking for) and bam, you have your result in a much more performant, inline to your application, manner

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

Sidebar

Related Questions

I have a mongo collection which has documents with two fields fieldA and fieldB,
I have a collection in mongo in which I am inserting data from Perl
I have an app and it needs to store a few simple objects that
I'm new to Java Mongo DB. I have to Store a huge amount of
My understanding of a NoSQL store such as Dynamo or Mongo etc. is that
It seems to me that when you are creating a Mongo document and have
I have a small Node.js HTTP server that does requests to a mongo database
I have a JSON file which has 40k documents, each document contains a date
Ideally, I have a Mongo document that looks like below. I want the ability
I have the following MongoDB object stored in my Mongo database: array ( '_id'

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.