gpt4 book ai didi

MongoDB 查找城市

转载 作者:可可西里 更新时间:2023-11-01 10:05:03 26 4
gpt4 key购买 nike

我是 mongoDB 的新手,正在尝试找出分配查询。我想查找给定城市名称的所有州。

我有一个文件来自这里 http://docs.mongodb.org/manual/tutorial/aggregation-examples/列出模型的位置

我试过

aggregate({$group : { _id: $"state"}} , {$match : {city : "BOSTON"}});

关于为什么这不起作用的任何提示?

最佳答案

我想答案是您不需要聚合来选择具有指定城市的州。

db.zipcodes.distinct('state', { city : 'BOSTON' })

关于性能 - distinctaggregate 的性能似乎几乎相同:

{ "ts" : ISODate("2013-05-04T06:52:02.772Z"), "op" : "command", "ns" : "test.$cmd", "command" : { "aggregate" : "zipcodes", "pipeline" : [ { "$match" : { "city" : "BELMONT" } }, { "$group" : { "_id" : { "state" : "$state" } } } ] }, "ntoreturn" : 1, "keyUpdates" : 0, "numYield" : 0, "lockStats" : { "timeLockedMicros" : { "r" : NumberLong(13990), "w" : NumberLong(0) }, "timeAcquiringMicros" : { "r" : NumberLong(10), "w" : NumberLong(5) } }, "responseLength" : 436, "millis" : 14, "client" : "127.0.0.1", "user" : "" }

对比

{ "ts" : ISODate("2013-05-04T06:52:11.169Z"), "op" : "command", "ns" : "test.$cmd", "command" : { "distinct" : "zipcodes", "key" : "state", "query" : { "city" : "BELMONT" } }, "ntoreturn" : 1, "keyUpdates" : 0, "numYield" : 0, "lockStats" : { "timeLockedMicros" : { "r" : NumberLong(12153), "w" : NumberLong(0) }, "timeAcquiringMicros" : { "r" : NumberLong(4), "w" : NumberLong(5) } }, "responseLength" : 262, "millis" : 12, "client" : "127.0.0.1", "user" : "" }

关于MongoDB 查找城市,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16367384/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com