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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T06:36:39+00:00 2026-05-21T06:36:39+00:00

I have collection as follows . { name : pqr , loc : [

  • 0

I have collection as follows .

{
 "name" : "pqr" ,
 "loc" : 
   [ 
    {"area" : "c" , "country" : "d"},
    {"area" : "w" , "country" : "r"}
   ]
}

I want to make which match such that only match the first element of array loc

that means if

  1. gives area as c or country d then it return document.
  2. gives area as w or country as r then does not return element

only match first element of mongo array

Is this possible in mongo ?

if some one knows plz reply

Thanks

  • 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-21T06:36:40+00:00Added an answer on May 21, 2026 at 6:36 am

    So if you want return only first matched element you should use limit(n) and queries like this:

    1.gives area as c or country d then it return document.

    db.items.find( { $or : [ {"loc.area": "c" } , 
                             {"loc.country ": "d" } ] } ).limit(1);
    

    2.gives area as w or country as r then does not return element

    db.items.find( { $or : [ {"loc.area":  { "$ne" : "w" } }, 
                             {"loc.country": { "$ne" : "r" } } ] } ).limit(1);
    

    If you want to search only in the first elements of nested array you can do it using positional operator by adding .0. -> loc.0.area.

    Update: I’ve misunderstand your question first. Now i see that you looking for loc.0.area.

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

Sidebar

Related Questions

I have a collection of data that looks as follows: id name c1 c2
I have 3 collection datatable that shows in this below Month: January ID NAME
I have a collection in mongo where objects appear as follows: { name:Scott, bio:Stumped,
I have a collection called geonames structured as follows: { ... loc: [50.729400634765625, 15.723899841308594]
Basically each entity would have a collection of feeding behaviors that it would follow.
for example I have collection foo of documents like that: {tag_cloud:[{value:games, count:10}, {value:girls, count:500}]}
I have two Collection objects, I want to associate each object of these two
I have a collection of the form: map<key, list<object> > I only ever insert
I have a custom collection defined in my window resources as follows (in a
I have a HTML snippet as follows, I want to take the 'article-form' div,

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.