小编Joh*_*ohn的帖子

MongoError $regex 必须是一个字符串

问题是,我的控制台出现错误:

{ [MongoError: $regex has to be a string]
  name: 'MongoError',
  message: '$regex has to be a string',
  waitedMS: 0,
  ok: 0,
  errmsg: '$regex has to be a string',
  code: 2 }
Run Code Online (Sandbox Code Playgroud)

基本上,我使用 Ajax 从我的 MongoDB 中获取数据,我在其中搜索用户。没有 Ajax,我的搜索功能可以正常工作,但我想搜索用户而不需要刷新网页,只需填写我的 HTML。这是我的所有代码:

服务器代码:

app.post("/searchresult", function(req, res){
    var thename = req.body.thename;
    LoginUser.find({
        $or: [

            {"firstname": {$regex: thename, $options: 'i'}},
            {"lastname": {$regex: thename, $options: 'i'}}
        ]
    }, function(err, searchedUser){
        if(err){
            console.log(err);
            res.redirect("back");
        } else {
            res.render("searchprofile", {foundUser: searchedUser});
        }
    });
});
Run Code Online (Sandbox Code Playgroud)

HTML代码:

<form class="form-inline" id="searchform" …
Run Code Online (Sandbox Code Playgroud)

html javascript ajax mongodb node.js

5
推荐指数
1
解决办法
4054
查看次数

NodeJS 集群不使用循环(在 Windows 上开发)

您好,我目前正在开发一个 MEAN 堆栈项目,我发现了在部署项目之前推荐的 Nodejs 集群模块。

我已经应用了它并做了一些 ApacheBenchmark,问题是,它只响应 1 个工作人员,它不会围绕我的其他 7 个工作人员轮换。

我在谷歌上搜索过这个问题,是的,Windows 默认不能进行循环,但是有没有办法在 Windows 中启用循环?

谢谢你!

cluster-computing node.js

2
推荐指数
1
解决办法
2963
查看次数

嵌套 EJS 标签。不工作

只是一个简单的问题,但我在谷歌上找不到任何内容。

所以在这里,

为什么这不起作用?

在第一行,最后一个'%>'变成白色在此输入图像描述

这是来自我的 NodeJS js 文件。当我渲染“loginuserprofile”时,我将 userProfile 变量传递给 EJS 这是来自我的 NodeJS js 文件 我会得到一个错误

错误:找不到“<%”的匹配关闭标记。

我不能使用嵌套的 <% %>?

谢谢你!

javascript ejs node.js web

1
推荐指数
1
解决办法
6595
查看次数

标签 统计

node.js ×3

javascript ×2

ajax ×1

cluster-computing ×1

ejs ×1

html ×1

mongodb ×1

web ×1