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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:51:41+00:00 2026-06-10T09:51:41+00:00

I want to query a document from a MongoDB database where the condition is

  • 0

I want to query a document from a MongoDB database where the condition is the outcome of a given calculation. I don’t know if this is understandable, an analog SQL query might help:

SELECT * FROM tasks AS t WHERE t.lastRun < (NOW() - t.maxAge)

Each tasks has a maxAge field which determines how often a task should run. If the maxAge is reached, the query should return that task which is then executed.

Because I lack the vocabulary to describe such a query it’s hard to find anything about this topic. Please be forgiving if this is mentioned somewhere. 🙂

My first reflex was: Let’s map the whole collection to contain the calculated threshold for each task, but this seems a bit too much for such a simple query. I hope this isn’ t the only solution to this. 🙂

  • 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-10T09:51:42+00:00Added an answer on June 10, 2026 at 9:51 am

    The problem with using the $where is that it can’t be indexed and there are currently issues with running javascript queries on the server, because the javascript engine is single threaded.

    A better approach in this case would be to

    re-write:t.lastRun < (NOW() – t.maxAge)
    to: (t.lastRun + t.maxAge) < NOW()

    The sum of t.lastRun and t.maxAge would be calculated and stored in an additional field upon insertion. Thus the resulting query would only require a single comparison.

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

Sidebar

Related Questions

In our project we want to query a document management system for a specific
I'm accepting dates from a wicket form - now I want query my DAO
I want DBSession.query(Article).group_by(Article.created.month).all() But this query can't using How do I do this using
I have a HTML document that I want to remove specific tags from, identified
I am trying to query this very complicated XML document using xDocument and LINQ
I want to extract some data from the database without refreshing a page. What
Suppose I want to query for only a certain attribute of all documents, something
i want query a file xml with linq, i want get all descendat of
I want to query the server to see if the date is different than
I want a query which will return a combination of characters and number Example:

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.