“Regex na consulta de Mongo” Respostas de código

mongodb $ em regex

// Find user who has the first_name equal with "name" (case insensitive)
const users = await User.find({
	first_name: {
    	$in: [new RegExp(`^${name}$`, 'i'))]
    }
})
florinrelea

MONGODB REGEX

{ <field>: { $regex: /pattern/, $options: '<options>' } }
{ <field>: { $regex: 'pattern', $options: '<options>' } }
{ <field>: { $regex: /pattern/<options> } }
Adorable Angelfish

Regex na consulta de Mongo

var search ='Neha';

db.members.find(name: new RegExp(search)) //For substring search, case sensitive. 

db.members.find(name: new RegExp('^' + search + '$')) //For exact search, case sensitive

db.members.find(name: new RegExp(search, ‘i')) //For substring search, case insensitive

db.members.find(name: new RegExp('^' +search + '$', 'i')); //For exact search, case insensitive
Shankar Anand

Respostas semelhantes a “Regex na consulta de Mongo”

Perguntas semelhantes a “Regex na consulta de Mongo”

Mais respostas relacionadas para “Regex na consulta de Mongo” em JavaScript

Procure respostas de código populares por idioma

Procurar outros idiomas de código