Mongodb finds no record of some names

Asked

Viewed 40 times

0

I’m pulling some data from Mongodb with Codeigniter and came across something strange... Some records are found and others are not. Debugging the code I saw that the problem was the name he 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 cannot find (sometimes) is the variable $alba. The name Camp-D (Radius) it cannot find, but exists in the database in the column albaPotential. Changing that name, putting another one as an example Nongrass (which is another record) think normally.

It seems to be I don’t know if it’s the - or the ( ), but he does not counter because of some character.

1 answer

0

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

See here some different characters that can sometimes get confused: https://en.wikipedia.org/wiki/Hyphen#Unicode

Try copying and pasting the value the way 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 contain a word. Here are some examples:

Exact text:

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

Contains:

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

Contains, tolerant of upper and lower case:

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

See more about more complex regular expressions here: http://turing.com.br/material/regex/introducao.html

Browser other questions tagged

You are not signed in. Login or sign up in order to post.