MongoDB does not find any names

0

I'm pulling some data from MongoDB with CodeIgniter and I came across a strange thing ... Some records are found and some are not. Debugging the code I saw that the problem was the name it is looking for, but it seems to be because of some character. My code:

$aggregate = array(
                 array('$match'=>array('culturaNormatizada'=>$cultura, 'ano'=>(int)$ano, 'albaPotential'=>$alba)),
                 array('$group'=>array('_id'=>'$'.$regiao))
                 );
$query = $this->mongo_db->aggregate('business_view_final', $aggregate);

The data that it can not find (sometimes) is the variable $ alba . The name Camp-D can not find it, but it exists in the database in the albaPotential column. Changing this name, putting another such as NonGrass (which is another record) normally finds.

It seems to be I do not know if it's the - or the ( ) , but it's not against some character.

    
asked by anonymous 18.01.2017 / 03:26

1 answer

0

There are several characters that are used as hyphen, it may not match the one in the document.

Here are some different characters that can sometimes be confused: link

Try copying and pasting the value as it is in the document, to make sure it's the same character.

You can also use regular expressions in a MongoDB query to tolerate differences such as uppercase and other characters, or even to search for a value that contains a word. Here are some examples:

Exact text:

{$match: {"albaPotential": "Camp-D (Raio)"}}

Contains:

{$match: {"albaPotential": /Raio/}}

Contains, tolerating case:

{$match: {"albaPotential": /raio/i}}

See more about more complex regular expressions here: link

    
19.01.2017 / 15:22