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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:31:57+00:00 2026-05-26T08:31:57+00:00

I have a collection containing documents. Each document has a part attribute containing an

  • 0

I have a collection containing documents. Each document has a part attribute containing an Array of Hash (documents). These documents may or may not have a _encwas attribute.

{ 
  _id : "00001",
  parts : [
    { _encwas: 1, body: "" },
    { body: "" }
  ]
},
{ 
  _id : "00002",
  parts : [
    { _encwas: 1, body: "" },
    { _encwas: 2, body: "" }
  ]
},
{ 
  _id : "00003",
  parts : [
    { body: "" },
    { body: "" }
  ]
}

Is there a quick way to find all records where at least one part contains a _encwas attribute?

The following query works

db.collection.find({ "parts.0._encwas" : { $exists : true } });

but I would love to find a way to replace 0 with any part. For example

db.collection.find({ "parts.*._encwas" : { $exists : true } });

The query should be as efficient as possible (I don’t mind if I need to create additional indexes) because I need to iterate more than 1M records.

  • 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-26T08:31:57+00:00Added an answer on May 26, 2026 at 8:31 am

    This seemed to work when I tried with your test data:

    db.collection.find( { "parts._encwas": { $exists : true } } )
    

    Moreover, you can find all documents containing _encwas having a specific value using:

    db.collection.find( { "parts._encwas": 4 } )
    

    …where 4 is the value…

    I believe the relevant part of the documentation is here: Dot Notation

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

Sidebar

Related Questions

I have a category collection and each category has a array of hashes containing
I have a domain object that has an attribute which is a collection containing
I have a DataGridView in a Winforms application containing a collection of items. Each
I have a collection of lists with each containing around 6 to 7 values.
I have a collection of Database objects, each containing collections of Schema objects and
So lets say I have an array containing a hash like this: [{head=> {title=>$20,000
I have Collection List<Car> . How to compare each item from this collection with
I'm planning to have collection of items stored in a TCollection. Each item will
At runtime, I have a collection of rows ( Row class). Each of them
I have a collection of Customers containing CustomerId, CustomerName and a few other columns.

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.