1

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

Community
  • 1
  • 1
Yongky Ali
  • 471
  • 4
  • 12

2 Answers2

1

You can use toUpperCase() of javascript, if you want to do find with uppercase letters. refer-doc.

Try the code below:

workers.find(
{
  "name": ("JOHN").toUpperCase()
});

Hope this will help.

Shrabanee
  • 2,706
  • 1
  • 18
  • 30
0

You can use $toUpper operator in mongodb.

    worker.aggregate([
           {$project: {"name":{$toUpper:"$name"}}},
           {$find:{"name":"JOHN"}}
    ]);
  • Sorry, but I am using mongoose to do database CRUD. I edited my post just to point out that. Do you have any solution using mongoose to operate in mongoDB? – Yongky Ali Apr 06 '17 at 08:39