猫鼬查询(Regex)(MongoDB和NodeJS)

时间:2020-07-21 00:26:09

标签: node.js mongodb mongoose mongodb-query

我想知道如何将正则表达式更改为 / ^ email。* /

我遇到困难,您能帮我吗?

// Retrieve all apis from the database.
exports.findAllPasswords = (req, res) => {
  const password = req.query.password;
  var condition = password ? { password: { $regex: new RegExp(password), $options: "i" } } : {};
  if (!password)
  res.json({ message: "Password param missing!" });

  api.find(condition)
    .then(data => {
    res.send(data);
    })
    .catch(err => {
      res.status(500).send({
        message:
          err.message || "Some error occurred while retrieving apis."
      });
    });
};

0 个答案:

没有答案