Re: MongoDB $or + $regex

2011-12-15 Thread AD7six


On Dec 14, 10:18 pm, Dave Lancea dlan...@gmail.com wrote:
 You can use the $or or $and operator to test multiple conditions of the
 same name:

 $conditions = array(
 '$or' = array(
 array(
 'date' = array(
 '$regex' = '/^arug/i',
 ),
 ),
 array(
 'date' = array(
 '$regex' = '/^bro/i',
 ),
 ),
 )
 );

 Note, the value of the '$or' key in the $conditions array is a normal,
 zero-indexed array which contains two values: an associative array
 containing a 'date' key. Confusing, I know.

Dave - did you read the code in the first post?

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: MongoDB $or + $regex

2011-12-15 Thread Dave Lancea
Hmm, I guess I misunderstood my original read of the original code. Our 
array formats look the same. Maybe the real problem is that using MongoRegex 
objects isn't necessarily, it worked for me to just use strings. However, I 
didn't test this using sub-items in a field, but on a field itself.

Also, AD7six has a good point in one of his posts, this doesn't need to be 
two separate $regex queries. It can be combined into one using the pipe 
operator. However, I thought I would give a solution for how to do two 
$regex queries in case someone needed it.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: MongoDB $or + $regex

2011-12-14 Thread Dave Lancea
You can use the $or or $and operator to test multiple conditions of the 
same name:

$conditions = array(
'$or' = array(
array(
'date' = array(
'$regex' = '/^arug/i',
),
),
array(
'date' = array(
'$regex' = '/^bro/i',
),
),
)
);

Note, the value of the '$or' key in the $conditions array is a normal, 
zero-indexed array which contains two values: an associative array 
containing a 'date' key. Confusing, I know.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: MongoDB $or + $regex

2011-12-13 Thread AD7six


On Dec 13, 1:44 am, RhythmicDevil rhythmicde...@gmail.com wrote:
 One more time?

what mongo query do you want to execute
what call to mongo's php driver achieves that
what cakephp code have you tried, what happened.

Somewhat difficult to help you if you don't say what's wrong (or even
what query you're _actually_ executing - use debug kit or the mongo
query log)

AD

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: MongoDB $or + $regex

2011-12-13 Thread AD7six


On Dec 10, 7:54 pm, RhythmicDevil rhythmicde...@gmail.com wrote:
 I have been going around and around with this this morning trying to
 sort out the correct syntax for an $or containing multiple $regex

 So in RockMongo I use this:

 {
 $or : [
         {ingredient : {$regex : /^aru/i}},
         {ingredient : {$regex : /^bro/i}},
         ]

why would you use 2 regexes for that /^(aru|bro)/i is the same thing

AD

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: MongoDB $or + $regex

2011-12-13 Thread AD7six


On Dec 13, 9:48 am, AD7six andydawso...@gmail.com wrote:
 On Dec 10, 7:54 pm, RhythmicDevil rhythmicde...@gmail.com wrote:

  I have been going around and around with this this morning trying to
  sort out the correct syntax for an $or containing multiple $regex

  So in RockMongo I use this:

  {
  $or : [
          {ingredient : {$regex : /^aru/i}},
          {ingredient : {$regex : /^bro/i}},
          ]

 why would you use 2 regexes for that /^(aru|bro)/i is the same thing

also - don't needlessly use the $regex key - that's probably your
error. You are _probably_ (who knows because you haven't shown the
executed query - I hope you've at least looked at it) generating
array('$regex' = array('$regex' = ...

{ingredient :  /^(aru|bro)/i} is all you need for the example yo'uve
shown

AD

 AD

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: MongoDB $or + $regex

2011-12-12 Thread RhythmicDevil
Bump!

On Dec 10, 1:54 pm, RhythmicDevil rhythmicde...@gmail.com wrote:
 I have been going around and around with this this morning trying to
 sort out the correct syntax for an $or containing multiple $regex

 So in RockMongo I use this:

 {
 $or : [
         {ingredient : {$regex : /^aru/i}},
         {ingredient : {$regex : /^bro/i}},
         ]

 }

 It returns two items from my DB

 However I cannot figure out the correct syntax to use to accomplish
 the same thing using Cake's MongoDB datasource. The method below only
 returns an item that matches on the last item in the $conditions
 array.

     public function test()
     {

          //'Ingredient.ingredient'
         $conditions = array();
         $conditions[] = array('Ingredient.ingredient' =
 array('$regex' = new MongoRegex('/^arug/i')));
         $conditions[] = array('Ingredient.ingredient' =
 array('$regex' = new MongoRegex('/^bro/i')));

         $query = array(
             'limit' = 15,
             'order' = array(
                 'Ingredient.ingredient' = 'asc',
                 'Ingredient.type' = 'asc'),
             'conditions' = array('$or' = $conditions)
         );

         var_dump($query);

         $ingredients = $this-Ingredient-find('all', $query);
         var_dump($ingredients);
         exit();
     }

 Any help would be appreciated.

 Thanks

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: MongoDB $or + $regex

2011-12-12 Thread RhythmicDevil
One more time?

On Dec 12, 8:07 am, RhythmicDevil rhythmicde...@gmail.com wrote:
 Bump!

 On Dec 10, 1:54 pm, RhythmicDevil rhythmicde...@gmail.com wrote:







  I have been going around and around with this this morning trying to
  sort out the correct syntax for an $or containing multiple $regex

  So in RockMongo I use this:

  {
  $or : [
          {ingredient : {$regex : /^aru/i}},
          {ingredient : {$regex : /^bro/i}},
          ]

  }

  It returns two items from my DB

  However I cannot figure out the correct syntax to use to accomplish
  the same thing using Cake's MongoDB datasource. The method below only
  returns an item that matches on the last item in the $conditions
  array.

      public function test()
      {

           //'Ingredient.ingredient'
          $conditions = array();
          $conditions[] = array('Ingredient.ingredient' =
  array('$regex' = new MongoRegex('/^arug/i')));
          $conditions[] = array('Ingredient.ingredient' =
  array('$regex' = new MongoRegex('/^bro/i')));

          $query = array(
              'limit' = 15,
              'order' = array(
                  'Ingredient.ingredient' = 'asc',
                  'Ingredient.type' = 'asc'),
              'conditions' = array('$or' = $conditions)
          );

          var_dump($query);

          $ingredients = $this-Ingredient-find('all', $query);
          var_dump($ingredients);
          exit();
      }

  Any help would be appreciated.

  Thanks

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php