You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Firestore数据库:如何在多个文档中搜索邮箱

根据邮箱查找文档ID的查询语句

假设使用MongoDB:

  • 若邮箱为顶层字段(如email):

    db.your_collection_name.find({ email: "mipaciente2@gmail.com" }, { _id: 1 })
    

    说明:第一个参数指定匹配条件,第二个参数是投影规则,仅返回文档ID(_id),减少不必要的数据传输。

  • 若邮箱嵌套在子文档中(如user.contact.email):

    db.your_collection_name.find({ "user.contact.email": "mipaciente2@gmail.com" }, { _id: 1 })
    
  • 若邮箱存在于数组字段中(如emails数组直接存储邮箱字符串):

    db.your_collection_name.find({ emails: "mipaciente2@gmail.com" }, { _id: 1 })
    
  • 若邮箱存在于数组对象中(如emails数组元素包含address字段):

    db.your_collection_name.find({ "emails.address": "mipaciente2@gmail.com" }, { _id: 1 })
    

假设使用Firestore:

db.collection("your_collection_name").where("email", "==", "mipaciente2@gmail.com").get()
.then((querySnapshot) => {
  querySnapshot.forEach((doc) => {
    console.log("目标文档ID:", doc.id);
  });
})

内容的提问来源于stack exchange,提问作者J.Salinas

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 03:55:25