我们如何在MongoDB数据库中的加密数据上实现搜索功能?

发布于 2025-02-09 08:09:23 字数 153 浏览 1 评论 0原文

我已经使用了 Mongoose-Field-Field-compryption 软件包,该软件包使我可以在存储和访问它之前对数据进行加密和解密。但是我需要直接在查询本身中为加密字段实现搜索功能。

这些字段是电子邮件ID,名称,手机号码,地址等。

I have used the mongoose-field-encryption package which allows me to encrypt and decrypt the data before storing and accessing it. But I need to implement search functionality for the encrypted fields directly in the query itself.

The fields are email id, name, mobile number, address, etc.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

神魇的王 2025-02-16 08:09:23

您可以使用汇总查询的$ function功能在查询中解密数据并应用过滤器。探索$ function 在这里 。像

Model.aggregate([
  {
    addFields: {
      decryptedEmail: {
        {
          $function: {
          body: function decrypt(email){ ... },
          args: ["$emailColumnName"],
          lang: "js"
        }
      }
    }
  },
  {
    $match: { decryptedEmail: emailToMatch }
  }
])

它所做的那样,创建一个名为decryptedemail的新字段,并且它的值是通过解密函数计算的,然后我们正在筛选出我们想要的电子邮件

You can use aggregate query's $function feature to decrypt data within the query and apply filters. Explore $function here. Something like

Model.aggregate([
  {
    addFields: {
      decryptedEmail: {
        {
          $function: {
          body: function decrypt(email){ ... },
          args: ["$emailColumnName"],
          lang: "js"
        }
      }
    }
  },
  {
    $match: { decryptedEmail: emailToMatch }
  }
])

what it does is, create a new field named decryptedEmail and the value of it is being computed by a decrypt function, and then we are filtering out the email we want

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文