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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:24:08+00:00 2026-06-10T22:24:08+00:00

I have the following documents in my MongoDB-database: {stats: [2,5,1]} {stats: [1,9,2]} Now I

  • 0

I have the following documents in my MongoDB-database:

{"stats": [2,5,1]}
{"stats": [1,9,2]}

Now I want to find those documents which have a stats-array that contains the values 2 and 1 (in that order). So only the first document should be found. A simple $all-query would return both documents. Is there a way to do this with MongoDB’s query-language?

Or lets assume the following documents:

{"stats": [{"val": 2, "position": 0},{"val": 5, "position": 1},{"val": 1, "position": 2}]}
{"stats": [{"val": 1, "position": 0},{"val": 9, "position": 1},{"val": 2, "position": 2}]}

Same question 🙂 Is there a way to query these documents to return only those which have a value 2 followed by a value 1 (take the position-value into account)?

I could probably use a $where-query, but the documentation says that this is not the preferred way (and is slow) 🙂

  • 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-10T22:24:09+00:00Added an answer on June 10, 2026 at 10:24 pm

    $all and $in do not take any ordering into account. Means: not doable with the standard query syntax.

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

Sidebar

Related Questions

Good day, If I have for example the documents which have the following fields
I have text documents like the following which contain single and multiple variables: title::
If I have the following 3 documents. How can I select the documents that
I am beginning with mongodb and have a collection with documents that look like
I have used following code in IndexController: $view = new Zend_View(array('scriptPath' =>'C:\Users\398853\Documents\NetBeansProjects\PhpProject3\application\views\scripts')); echo $view->render('index.phtml');
I have a MongoDB collection with documents in the following format: { _id :
I have following problem that in a transformation (which is completely done in memory)
I used rails3.2.3 with mongoid gem for mongodb database. I have following code user
I've recently updated to Mongodb 2.2.0 and found that the following query now no
I have the following document in a couchdb database: { _id: 000013a7-4df6-403b-952c-ed767b61554a, _rev: 1-54dc1794443105e9d16ba71531dd2850,

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.