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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:16:07+00:00 2026-05-27T23:16:07+00:00

mongodb and or combo Similar to this except I’m using php and getting [MongoCursorException]

  • 0

mongodb and or combo Similar to this except I’m using php and getting [MongoCursorException] $or array must contain objects.

Also read this http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%24or

How can one nest an “AND” inside of an “OR” in MongoDB via PHP? Here is my conditions argument (via var_export):

'group_id' => '4eec13b5-aeb4-48ee-9619-449125af0e18',
'$or' => 
array (
  0 => 
  array (
    0 => 
    array (
      'active' => 0,
      'user_id' => '4eea7b76-5d34-4036-8344-120c0aaa1bdc',
    ),
  ),
  1 => 
  array (
    1 => 
    array (
      'active' => 1,
    ),
  ),
)

Need list of posts that are in a group id AND are active OR (belong to the user AND are not active).

Extremely easy in SQL but whichever variation I try in the MongoDB via PHP query I get the $or error. Is this possible? Is an $and required?

  • 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-27T23:16:08+00:00Added an answer on May 27, 2026 at 11:16 pm

    your query is just incorrect. In JSON, it would look like

    { 
       "group_id" : "4eec13b5-aeb4-48ee-9619-449125af0e18",
       "$or" : [ 
                        [ { "active" : 0, "user_id" : "4eea7b76-5d34-4036-8344-120c0aaa1bdc" } ],
                        [ null, { "active" : 1 } ] 
               ]
    }   
    

    for group id AND are active OR (belong to the user AND are not active), it should be represented somewhat as :

    { 
       "group_id" : "4eec13b5-aeb4-48ee-9619-449125af0e18",
       "$or" : [ 
                        { "active" : 0, "user_id" : "4eea7b76-5d34-4036-8344-120c0aaa1bdc" },
                        { "active" : 1 } 
               ]
    }   
    

    More or less, it will look like this in PHP

    array(
    'group_id' => '4eec13b5-aeb4-48ee-9619-449125af0e18',
    '$or' => 
         array (
            0 => 
               array (
                   'active' => 0,
                   'user_id' => '4eea7b76-5d34-4036-8344-120c0aaa1bdc',
               ),
            1 => 
               array (
                   'active' => 1,
               )
         ),
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently using MongoDB's MapReduce to generate hourly ad view counts like this:
Using mongodb with the NoRM driver I have this document: { _id : ObjectId(0758030341b870c019591900),
Using MongoDB... If I have an array of ids in one field, can I
I'm using MongoDB and we are really happy with this DB. But recently our
Using MongoDB C# driver ( http://github.com/samus/mongodb-csharp ), seems that I'm unable to get the
I'm currently using MongoDB to record application logs, and while I'm quite happy with
I'm just learning MongoDB and MongoMapper. This is on Rails 3. I created a
I am using MongoDB v1.4 and the mongodb-csharp driver and I try to group
I'm building a Rails application using MongoDB as the back-end and MongoMapper as the
In MongoDB, using $type , it is possible to filter a search based on

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.