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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:47:20+00:00 2026-05-29T15:47:20+00:00

According to mongodb doc, syntax for $elemMatch would be, t.find( { x : {

  • 0

According to mongodb doc, syntax for $elemMatch would be,

t.find( { x : { $elemMatch : { a : 1, b : { $gt : 1 } } } } )

I have tried and it works fine.
The above means that, it can find if an object {a:1, b:’more than 1′} exist in the array x.

I have a requirement, where I need to figure out, if all the objects in an array exist in the database or not.

for example, let’s say I have an array,

a=[{a:1, b:2},{a:3, b:4}, {a:5, b:6}]

and I need to find out if x contains all of them.

t.find( { x : { $elemMatch : { a : {$all:[1]}, b : {$all:[2]} } } } ) and it finds out all x containing {a:1, b:2}

But if I try, t.find( { x : { $elemMatch : { a : {$all:[1,3]}, b : {$all:[2,4]} } } } ), it fails. I know this is not correct.
Is there any way I can achieve this ?
Ideallt, it should be,

t.find( { x : { $elemMatch : {$all:[ {a:1, b:2}, {a:3, b:4}] } } )

I tried, it does not work.

  • 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-29T15:47:21+00:00Added an answer on May 29, 2026 at 3:47 pm
    t.find({$and:[{a:{$elemMatch:{a:1, b:2}}}, {a:{$elemMatch:{a:3, b:4}}}, {a:{$elemMatch:{a:5, b:6}}}]})
    

    It isn’t a particularly high performance option though.

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

Sidebar

Related Questions

According to what I have found so far, I can use the following code:
We have a lot of data, decided to use mongodb and it works great.
According to the manpage, -l in ulimit means The maximum size that may be
I have a mongodb server in production serving on an EC2 instance. According to
According to this discussion , the iphone agreement says that it doesn't allow loading
According to Wikipedia, on the Comparison of programming languages page, it says that F#
According to the feedparser documentation , I can turn an RSS feed into a
I have 100000 documents and I need to retrieve the top 10 documents that
I have done a simple experiment to test MongoDB's performance and disk usage. I
According to what I've heard, integer values that are not the processor's word size

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.