Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Need MongoDB query in PHP
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Jay Prakash Mishra  
View profile  
 More options Nov 2 2012, 6:47 am
From: Jay Prakash Mishra <jayprakas...@gmail.com>
Date: Fri, 2 Nov 2012 03:47:57 -0700 (PDT)
Local: Fri, Nov 2 2012 6:47 am
Subject: Need MongoDB query in PHP

Dear Friend,

I need a customize query criteria for find method. My condition of query is
like below :

Mysql Query :

Select * from students where (state='xx' and city='yy') OR (university='mm'
and college='nn').

Please provide above query in mongodb. However I tried to write this in
Mongo as below :

array(
       '$or'=>array(
               '$and'=>array(
                       array('state' => array('$in' =>
array('Delhi','Bihar'))),
                       array('city' => array('$in' =>
array('Delhi','Bihar'))),
               ),
               '$and'=>array(
                               array('university' => array('$in' =>
array('New Delhi','Patna'))),
                               array('college' => array('$in' => array('New
Delhi','Patna')))
               )
       )
)

But it produces fatal errors :

Fatal error: Uncaught exception 'MongoCursorException' with message '$and
expression must be a nonempty array'  ...............................

Please help me.

Regards
Jay


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Sam Millman  
View profile  
 More options Nov 2 2012, 8:06 am
From: Sam Millman <sam.mill...@gmail.com>
Date: Fri, 2 Nov 2012 12:06:01 +0000
Local: Fri, Nov 2 2012 8:06 am
Subject: Re: [mongodb-user] Need MongoDB query in PHP

The default operator between array elements in MongoDB is $and, as such you
can actually remove those $and's and use only the $or. Also you cannot have
duplicate array keys within a single array as such only one $and would be
seen anyway.

On 2 November 2012 10:47, Jay Prakash Mishra <jayprakas...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jay Prakash Mishra  
View profile  
 More options Nov 2 2012, 8:19 am
From: Jay Prakash Mishra <jayprakas...@gmail.com>
Date: Fri, 2 Nov 2012 17:47:04 +0530
Local: Fri, Nov 2 2012 8:17 am
Subject: Re: [mongodb-user] Need MongoDB query in PHP
Hi Sam,

I have written the like below after you suggestion :

array(
       '$or'=>array(
               array(
                                   array('pState' => array('$in' => array('Delhi','Bihar'))),
                                   array('pCity' => array('$in' => array('New Delhi','Patna'))),
               ),
              array(
                                   array('boardPercent_10' => array('$gt' => 50)),
                                   array('boardName_10' => array('$in' => array('cbse','icse')))
               )
       )
)

But it is still producing error?

--
Thanks & Regards
 Jay Prakash | Software Engineer
 M.  N. - 9953477708

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Sam Millman  
View profile  
 More options Nov 2 2012, 8:43 am
From: Sam Millman <sam.mill...@gmail.com>
Date: Fri, 2 Nov 2012 12:42:55 +0000
Local: Fri, Nov 2 2012 8:42 am
Subject: Re: [mongodb-user] Need MongoDB query in PHP

You've got a few too many arrays there, the syntax for an $or is $or =>
array(array(//condition), array(//condition)) with the condition parts
being $and and the sub arrays in the $or array being $or

On 2 November 2012 12:17, Jay Prakash Mishra <jayprakas...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »