Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js Typeorm、MongoDB和where操作符_Node.js_Mongodb_Express_Nestjs_Typeorm - Fatal编程技术网

Node.js Typeorm、MongoDB和where操作符

Node.js Typeorm、MongoDB和where操作符,node.js,mongodb,express,nestjs,typeorm,Node.js,Mongodb,Express,Nestjs,Typeorm,[使用MongoDB类型键入表单]。您好,我有一个数据库,其中每个用户都有一个电子邮件道具,现在我想查找电子邮件以“test”开头的所有用户,例如,返回值应该是user[{email:'test1'},{email:'test2'},…],但我无法在这里提取这些实体我如何执行查询: const users = await this.usersRepository.find({ where: `"email" LIKE 'test%'`, }); 但是这段代码返回

[使用MongoDB类型键入表单]。您好,我有一个数据库,其中每个用户都有一个电子邮件道具,现在我想查找电子邮件以“test”开头的所有用户,例如,返回值应该是user[{email:'test1'},{email:'test2'},…],但我无法在这里提取这些实体我如何执行查询:

 const users = await this.usersRepository.find({
    where: `"email" LIKE 'test%'`,
 });
但是这段代码返回整个用户集合。我还尝试了以下方法:

    const users = await this.usersRepository.find({
        where: {
            email: Like('test')
        }
    });
我还尝试了以下方法:

    const users = await this.usersRepository.find({
        where: {
            email: Like('test')
        }
    });
这一个返回空数组[]


即使我尝试使用精确匹配,例如('test21@abv.bg“),仍然返回空数组

我如何能做到让所有用户的电子邮件开始与'测试'提前感谢

对于MongoDB,使用正则表达式

const users = await this.usersRepository.find({
    where: {
        email: new RegExp(`^${userEmail}`);
    }
});

返回空array@AndonMitev这似乎很奇怪。尝试从“用户”运行原始SQL SELECT*,其中“email”如“test%”,以再次检查您的数据是否没有问题。我会尝试将您的条件直接作为find方法参数,例如find({email:LIKE('test%'))});但我想这不会有什么区别。参考:是的,我使用MongoDB与TypeORM@AndonMitev它改变了一切。您需要在案例{email:/^test/}中使用正则表达式