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

  • Home
  • SEARCH
  • 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 9204615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:45:07+00:00 2026-06-17T23:45:07+00:00

I have a blog application. I need to make a MongoDB query (SQL is

  • 0

I have a blog application. I need to make a MongoDB query (SQL is fine, I’ll translate it), to get a specific post in the blog, and the immediate posts made before and after that post.

For instance, given this list of posts:

12/01/13 - Foo
15/01/13 - Bar
17/01/13 - Baz
27/01/13 - Taz

How do I write a query so that I get one of these, i.g Bar, and the immediate siblings Foo and Baz?

I’d like to do this without making three different queries to the database, for performance reasons.

In my application I fetch a single post like this:

model.findOne({
    date: {
        $gte: new Date(2013, 0, 15),
        $lt: new Date(2013, 0, 15, 24)
    },
    slug: 'Bar'
}, function(result){
    return { entry: result };
});
  • 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-17T23:45:08+00:00Added an answer on June 17, 2026 at 11:45 pm

    Here’s one possibility (involving 2 queries, one to find the primary post, and the second to find the nearest doc):

    • Treat the data/posts as if it were a doubly-linked list.
    • You’ll need to store reference IDs as links to the “previous” and “next” posts in each post document (array). This makes inserts a tiny more complex, but inserting a “new” blog post by date somewhere in the past seems unlikely.
    • Index the link field
    • Search for documents having the id of the primary document $in the link field
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have my rails application and I have blog posts in my application.
I have a wordpress blog setup inside of my Rails application, i need to
I have created a blog application using Ruby on Rails which includes the ability
I have a really simple blog application and I want to add a really
I have created a simple blog application with Ruby on Rails. The applications consists
I have built a very simple blog application using Ruby on Rails. New to
I'm trying to do blog application and I want main page to have this
I have a cakePhp application built, and now I'm creating a simple blog based
I have a blog I wrote in PHP, and need to shorten the latest
i have wordpress blog in my custom built website, i am displaying some posts

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.