search function in mongoDB with case-insensitive query [duplicate] - mongodb

This question already has answers here:
case insensitive find in mongodb for usernames in php
(2 answers)
Closed 8 years ago.
I am doing with function in mongoDB, now it's have problem with case-insensitive data. this is my code in function
$where = array(TblFact::Fou_Name => array('$regex' =>$SearchNameFactory));
this code when data in uppercase and i search by lowercase is return null. So anyone can help me to find solution for case-insensitive query ?
I am looking to see your replay soon. Thanks ...

Thanks everyone for help me , now my problem have been resolve by
$where = array(TblFact::Fou_Name => new MongoRegex("{$SearchNameFactory}/i"));
hope it can help to anyone who meet problem like me
thanks

Related

Lucene.NET version 4.8 beta casing issue [duplicate]

This question already has answers here:
Java Lucene 4.5 how to search by case insensitive
(3 answers)
Closed 3 years ago.
I'm using Lucene.NET version 4.8 (beta) for a little search task in a solution I'm doing, but have problems searching case insensitive. I know that Lucene isn't case insensitive, but when using the StandardAnalyzer, it should lowercase the data stored (according to the documentation here StandardAnalyzer), as long as you make sure the queries are done right.
So any idea what I'm doing wrong here? I've stored the data "Kirsten" in a field in 4 different documents, and when searching for (lowercased) "kirsten" I get no hits, but when searching for "Kirsten" I get the expected 4.
Here's my query code:
query = query.ToLowerInvariant();
BooleanQuery q = new BooleanQuery {
new BooleanClause(new WildcardQuery(new Term(FieldNames.Name, query + WildcardQuery.WILDCARD_STRING)), Occur.SHOULD),
new BooleanClause(new WildcardQuery(new Term("mt-year", query)), Occur.SHOULD),
new BooleanClause(new WildcardQuery(new Term("mt-class", query + WildcardQuery.WILDCARD_STRING)), Occur.SHOULD)
};
And the issue is that the users would always write the lowercase version, and expect it to find both lower- and upper-case.
As #Peska wrote in the comments, this was a case of using StringField instead of TextField when adding the document (and data) to Lucene.
Once I switched to using TextField, everything worked as expected.

How to write query with LIKE in MongoDB? [duplicate]

This question already has answers here:
How to query MongoDB with "like"
(45 answers)
Closed 4 years ago.
The document looks like:
{
"_id" : ObjectId("5c11389782c3c3751def6a68"),
"\"dname\"" : "\"W6PJBu7wC0Demyl86pd8Um5NHk3ukqsdtVA6 \""
}
I've searched a lot and found that I can write it as: /. For example, I need to get all document where dname starts with c, for this I do:
db.getCollection('flat').find({"\"dname\"" : "\"c/"})
Also I've tried this:
db.getCollection('flat').find({"\"dname\"" : "/^\"c/"})
but it does not work. What I do wrong?
You need to use regexes
For example, to find records with dname starting with c: db.getCollection('flat').find({"\"dname\"" : /^\"c/})

Reverse search at mongodb

I have tried to search around for clues but didn't find any.
Please let me ask a question about reverse search for mongodb.
I have a collection that contain a phone prefix, let say bellow.
{"prefix":"1234"}
and i am trying to make it hit with value like 12341111 or 12342222 ...
in MySQL i can do it with below SQL.
SELECT * from phoneprefix where ‘12341111’ like concat(prefix,’%’)
Is there anyway to make it possible at mongodb ?
Thanks for reading my post and please have a nice day !
The only way I can see to do this is to use the performance-challenged $where operator:
db.phoneprefix.find({$where: function() {
return (new RegExp('^' + this.prefix)).test('12341111');
}});
You could use $regex in MongoDB.

CakePHP, MongoDB: How to search field from Collection

I want to implement functionality that will search the record from mongoDB. I am using ichikaway plugin.
I tried the cakephp like clause mentioned here, but did not worked for me :(.
please let me if there is any approach to achieve this.
Thanks in advance
After doing search around I have found solution
$conditions = array('field_name' => new MongoRegex('/'.$value.'/i'));
where i trans to case-insensitive.

Get the Actual SQL of a Prepared Statement with mysqli? [duplicate]

This question already has answers here:
Is there a way to see a prepared query as it will be executed on the database? [duplicate]
(4 answers)
Closed 4 years ago.
Is there any way to get the actual SQL that is the result of preparing a statement when using the mysqli extension?
My problem:
I am using prepared statements. In all cases, they SHOULD update a record. I am not catching any errors. However, when I check for affected rows, there are none. So, I want to see the actual SQL that would be executed as a result of the prepare statement.
Is there any way to do this? I've check the mysqli reference docs, but they don't seem to have anything.
While I was looking for a Mysqli specific answer I found that all refer to PDO only thus not addressing the issue with using the ? placeholder.
So here I post my contribution of a simple function to replace all the ? for the parameters. (PHP 7)
function addParamsToSQL ( string $SQL, array $params ) : string {
foreach($params as $value)
$SQL = preg_replace ( '[\?]' , "'" . $value . "'" , $SQL, 1 );
return $SQL;
}