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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:20:21+00:00 2026-05-27T17:20:21+00:00

I have a Mongo collection where each document has a set of unique embedded

  • 0

I have a Mongo collection where each document has a set of unique embedded keys:

{
    Facebook :
    {
        Archived:'False' //non unique
        'fan_count_December_19_2011':12345, //unique
        'unique_views_count_December_19_2011':12345, //unique
        'post_count_December_19_2011':12345, //unique
        ...
        ...
    }
}

We look up these documents with the following query:

db.metrics.find({
    {'Facebook.fan_count_December_19_2011' : {'$ne':null}},'Archived':'False'}
}
).limit(1)

The problem is, with 6,000 such documents, it’s a little slow. Looking at the Explain() log; each query takes on average 0.06 seconds to execute and it’s doing a full collection scan everytime.
Our service has to do the above query about 100 times (for 100 distinct keys); which at 0.06 p/s adds up to 6 seconds per call (not including the overhead of the site serving the data).
Sending all the keys over in one batch and doing one large query would require a major rewrite of the data layer; which I’m trying to avoid due to a tight deadline coming up.
I’ve been looking through the documentation, and there doesn’t seem to be a way to have a key-based index. The documentation says you can index on an embedded key; but that seems to only index the values. It also doesn’t do me much good; since each key in the system is unique; there’d have to be an index for each new key.

Short of re-designing our document structure (which would require a major change); is there anyway I can do to speed up this query against the existing collection in it’s current format?

Any constructive input is greatly appreciated.

Thanks,
Frank

  • 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-27T17:20:22+00:00Added an answer on May 27, 2026 at 5:20 pm

    Assuming you set your Archived field to true after you have processed a document, you could create an index on just the Archived field.

    Normally you wouldn’t create an index on a field with low cardinality, but it might work for you in this case, but only on the assumption that there are not very many documents where the Archived field is false.

    In the longer run you should redesign your document so you don’t have so many unique field names (something along the lines of Iain’s suggestion of a “Facebook.date” field). That way you have something you can create an index on.

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

Sidebar

Related Questions

So I have an embedded document that tracks group memberships. Each embedded document has
I have a Mongo collection called documents which has the following structure: { name:
We have a collection of log data, where each document in the collection is
I have a problem with relationships persisting in an embedded document. Here is the
I'd like to query a mongo collection for records which either don't have a
I have got mongo db using only one collection and consuming average cpu usage
If I have a Company collection which contains embedded Divisions: { _id: 1 _t:
Can someone point me in the right direction, i have a Collection (Forms) each
I have a number of different documents in a mongo collection. The attrs are
i have a mongo collection like this: { A2_AboutMe: , A2_Attributes: |av|nv|, A2_Birthday: ,

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.