【问题标题】:pymongo db.command exclude fields / projectionpymongo db.command 排除字段/投影
【发布时间】:2017-01-28 00:38:13
【问题描述】:

我正在尝试使用执行 geoNear 搜索的 PyMongo 编写对 db.command() 的调用,并且我想排除字段。 Mongo 站点上的 db.runCommand 文档和 PyMongo 文档都没有解释如何实现这一点。

我了解如何使用 db.collection.find():

response = collection.find_one(
  filter = {"PostalCode": postal_code},
  projection = {'_id': False}
)

但是,在使用 db.command() 执行 geoNear 搜索时,我无法在任何地方找到任何示例:

params = {
  "near": {
    "type": "Point",
    "coordinates": [longitude, latitude]
  },
  "spherical": True,
  "limit": 1,
}

response = self.db.command("geoNear", value=self._collection_name, **params)

谁能提供有关在使用 db.command 时如何排除字段的见解?

【问题讨论】:

    标签: python mongodb pymongo


    【解决方案1】:

    geoNear 命令没有“投影”功能。它总是返回整个文档。有关其选项,请参阅 geoNear 命令参考:

    https://docs.mongodb.com/manual/reference/command/geoNear/

    【讨论】:

      猜你喜欢
      • 2015-04-01
      • 2014-05-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-18
      • 1970-01-01
      • 2022-12-10
      • 2012-08-12
      相关资源
      最近更新 更多