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

如何编写仅查询单个列的JSON格式MongoDB查询语句

MongoDB JSON格式单字段查询语句示例

要仅从集合中查询单个列的数据,需在你的查询结构中添加投影配置,明确指定要返回的目标字段。

完整模板示例

{
    "collection": "<collection_name>",
    "query": {
        "mobile" : { "$in": [ "<mobile_number>" ]  }
    },
    "projection": {
        "<target_column>": 1,
        "_id": 0
    }
}

参数说明

  • <collection_name>:替换为你的MongoDB集合名称
  • <mobile_number>:替换为需要匹配的手机号
  • <target_column>:替换为你要单独查询的列名
  • "_id": 0:可选配置,若不需要返回默认的_id字段则保留,需要则删除该行

实际使用示例

假设要从users集合中,查询手机号为13800138000的文档,仅返回email列:

{
    "collection": "users",
    "query": {
        "mobile" : { "$in": [ "13800138000" ]  }
    },
    "projection": {
        "email": 1,
        "_id": 0
    }
}

内容的提问来源于stack exchange,提问作者Aman

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.28 03:12:33