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

The Archive Base Latest Questions

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

I’m using Doctrine ODM with mongoDB. I’m trying to do queries like : $queryBuilder->field(‘array_field’)->in(‘even_value_1’,

  • 0

I’m using Doctrine ODM with mongoDB.

I’m trying to do queries like :

$queryBuilder->field('array_field')->in('even_value_1', 'event_value_2');
$queryBuilder->field('array_field')->in('odd_value_1', 'odd_value_2');

The idea is to select all documents that have in their

array_field(event_value_1 OR event_value_2) AND (odd_value_1 OR odd_value_2)

With the syntax I’m using, I’m getting the documents that have

event_value_1 OR event_value_2 OR odd_value_1 OR odd_value_2

Any ideas on how to proceed or if it is possible ?

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

    It seems that the $and operator is just not currently available in MongoDB.
    The $and operator is in 1.9.1 (unstable version)

    Here is the ticket for the feature request :
    https://jira.mongodb.org/browse/SERVER-1089

    Currently (1.8.x) the only solution seems to use multiple “$or” statments like :

    even_value_1 AND odd_value_1 
    OR even_value_1 AND odd_value_2
    OR even_value_2 AND odd_value_1
    OR event_value_2 AND odd_value_2
    

    EDIT: Here is some code to help future users

    First, we need a function to transform our

    array_field(event_value_1 OR event_value_2) AND (odd_value_1 OR odd_value_2)
    

    to

    even_value_1 AND odd_value_1 
    OR even_value_1 AND odd_value_2
    OR even_value_2 AND odd_value_1
    OR event_value_2 AND odd_value_2
    

    Here are the needed functions

    /**
     * $pArray for our example should be like array(array(event_value_1, 
     *                 event_value_2),array(odd_value_1, odd_value_2))
     */
    function transform_and_group_of_or_to_or_group_of_and ($pArray)
    {
        //Make sure we have sequential numerical indexes
        sort($pArray);
    
        $maxIndices = array();
        foreach ($pArray as $key=>&$values){
            //Make sure we have sequential numerical indexes
            sort($values);
    
            $maxIndices[$key] = count($values)-1;
            $arIndices[$key] = 0;
        }
    
        $groupCount = count($pArray);
        $groupOfAnd = array();
    
        do {
            $newGroup = array();
            for ($i=0; $i<$groupCount; $i++){
                $indice = $arIndices[$i];
                $sousTab = $pArray[$i];
                $newGroup[] = $sousTab[$indice];
            }
            $groupOfAnd[] = $newGroup;
        } while(increment_numbers($arIndices, $maxIndices));
    
        return $groupOfAnd;
    }
    
    function increment_numbers(& $arIndices, $maxIndices){
        //Raise the last indice
        $arIndices[count($arIndices)-1]++;
    
        $check = true;
        for ($i=count($arIndices)-1; (($i>=0) && ($check === true)); $i--){
            if ($arIndices[$i] > $maxIndices[$i]){
                if ($i > 0){
                   $arIndices[$i-1]++;//increment the upper indice element
                } else {
                    return 0;
                }
                $arIndices[$i] = 0;
                $check=true;
            }else{
                $check = false;
            }
        }
        return true;
    }
    

    For the Doctrine ODM part :

        if (count($arGroupedCritere)) {
            $arGroupedCritere = transform_and_group_of_or_to_or_group_of_and($arGroupedCritere);
                foreach($arGroupedCritere as $arCritere) {
                    $queryBuilder->addOr($queryBuilder->expr()->field('_criteres')->all($arCritere));
                }
        }
    

    Hope this helps

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

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
In order to apply a triggered animation to all ToolTip s in my app,
I want use html5's new tag to play a wav file (currently only supported
I want to count how many characters a certain string has in PHP, but
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string

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.