Search for similarity in Mongo

Asked

Viewed 50 times

1

I need to make a find in my Mongo by likeness example

[
{
    "nome" : "Erick",
    "codigo" : 1,
    "periodos" : 10
},
{
    "nome" : "Erica",
    "codigo" : 1,
    "periodos" : 10
},
{
    "nome" : "Arthur",
    "codigo" : 2,
    "periodos" : 5
}
]

In my find then I will receive 'Eric'

cursos.find({
nome: "eric"
}

I want to return the two elements that contain these String or is the data of Erick and Erica

1 answer

4


Can use regex:

cursos.find({nome: /^Eric/})

  • Passing the String directly works but for me to use a variable that contains the String how do ? And I still want the search to be case-sensitive

  • This link in the answer contains all this information, if you have difficulty implementing any, open a new question with the code you are trying. Good Luck.

Browser other questions tagged

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