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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:52:57+00:00 2026-06-18T09:52:57+00:00

I have mongodb collection like this: { _id : ObjectId(51111618b419e37023f5070c), checkCode : statusCode, checkDate

  • 0

I have mongodb collection like this:

{
    "_id" : ObjectId("51111618b419e37023f5070c"),
    "checkCode" : "statusCode",
    "checkDate" : ISODate("2013-02-05T18:24:24.927Z"),
    "domain" : ObjectId("511102021ffae419c2363c33"),
    "pageUrl" : "/index.html",
    "checkResult" : "404"
}

The collection can has many records with same domain, pageUrl, checkCode but different checkResult (or the same) and different checkDate (date of the check).

So I need to select only last by date checkResult by pageUrl and checkCode in given domain. What is the best and faster way to do this (there could be lots of records by domain and check results) ? Should I use group or map/reduce? Distinct works too slowly…

  • 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-18T09:52:58+00:00Added an answer on June 18, 2026 at 9:52 am

    You could use the aggregation framework here like so:

    db.col.aggregate([
        {$match:{domain: ObjectId("511102021ffae419c2363c33")}},
        {$sort:{checkDate:-1}},
        {$group: {_id: {pageUrl: '$pageUrl', checkCode: '$checkCode'}, checkResult: {$first: '$checkResult'}}}
    ])
    

    Using the $match and $sort with the $first operator allows for index usage which could make a performant group for at least a substantial number of records.

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

Sidebar

Related Questions

I have a document collection like this: { _id : ObjectId(4fb21439f31dfd122ce39c4a), Name : Freelander
If I have a mongodb collection users like this: { _id: 1, name: {
I have the following mongodb structure { _id: ObjectId(507c80a143188f9610000003), date: ISODate(2012-10-15T21: 31: 13.0Z), uid:
I have big collection of tweets stored in MongoDB. Tweets look like this one:
Say I have a collection of users like this:- { _id : 1234, Name
I have a sorted (Mongodb) collection of objects: {_id: ObjectId(...), person: Homer, order: 1},
I have a MongoDB collection called employees where there are documents like this: {
I have 10000 documents in one MongoDB collection. I'd like to update all the
I created a test MongoDB collection sampleCollection with documents which looks like: _id :
I have the following data structure in MongoDB: { _id : ObjectId( xy ),

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.