Reputation: 492
I am very familiar with Oracle when suddenly i had to create a project with MongoDB database. I am using mongoose to connect to my MongoDB. My question is, is that possible to match find condition before doing a query?
For example, i got this name : John
in my MongoDB then i just need to do this by Oracle SQL.
SELECT * FROM MY_SCHEMA.WORKERS WORKER
WHERE UPPER(WORKER.NAME) = 'JOHN'
In mongoDB, all I know and can do is this.
var mongoose = require('mongoose');
mongoose.connect('localhost:27017/myDB');
workers.find(
{
"name": "JOHN"
}
);
I have been searching for solution and can't find one. Is there any way to set name
's value to upper case to match the result i needed?
Any help would be appreciated :)
EDIT : I found the solution to this problem by using RegExp() for mongoose. RegExp will make my mongoDB docs case-insensitive to match my query's parameter. More details in this answer. https://stackoverflow.com/a/9824712/7498283
Upvotes: 1
Views: 272
Reputation: 1
You can use $toUpper operator in mongodb.
worker.aggregate([
{$project: {"name":{$toUpper:"$name"}}},
{$find:{"name":"JOHN"}}
]);
Upvotes: 0