- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
请观察 mongo shell:
> map
function map() {
if (this.server_location[0] == -77.0367) {
emit(this._id, this);
}
}
> reduce
function reduce(key, values) {
return values[0];
}
> db.static.mapReduce(map, reduce, {out: 'x', query: {client_location:{$near:[-75.5,41.89], $maxDistance: 1}}})
{
"result" : "x",
"timeMillis" : 43,
"counts" : {
"input" : 100,
"emit" : 0,
"reduce" : 0,
"output" : 0
},
"ok" : 1,
}
> db.static.find({client_location:{$near:[-75.5,41.89], $maxDistance: 1}, $where: "this.server_location[0] == -77.0367" }).count()
7
>
我首先运行一个 map-reduce 实现,然后运行与查询相同的东西。结果不同。我做错了什么?
编辑
我已经像这样更改了 map 功能:
function map()
{
if (this.server_location[0] < -77 && this.server_location[0] > -78)
{
print(this._id + ": server_location[0] = " + this.server_location[0]);
}
if (this.server_location[0] == -77.0367)
{
emit(this._id, this);
}
}
运行 map-reduce 在 mongod 控制台上打印以下内容:
1412262185: server_location[0] = -77.8586
1412493418: server_location[0] = -77.8586
1412497409: server_location[0] = -77.8586
1412559515: server_location[0] = -77.8586
1412666474: server_location[0] = -77.6114
1412895269: server_location[0] = -77.6114
1412962473: server_location[0] = -77.6114
另一方面,使用 $where
语句的查询会产生以下结果:
/* 0 */
{
"_id" : 1411941588,
"server_location" : [-77.0367, 38.8951],
"client_location" : [-75.6485, 41.4201]
}
/* 1 */
{
"_id" : 1412382406,
"server_location" : [-77.0367, 38.8951],
"client_location" : [-75.728, 41.4486]
}
/* 2 */
{
"_id" : 1412987742,
"server_location" : [-77.0367, 38.8951],
"client_location" : [-75.8962, 41.2808]
}
/* 3 */
{
"_id" : 1412988363,
"server_location" : [-77.0367, 38.8951],
"client_location" : [-75.8962, 41.2808]
}
/* 4 */
{
"_id" : 1412989085,
"server_location" : [-77.0367, 38.8951],
"client_location" : [-75.8962, 41.2808]
}
/* 5 */
{
"_id" : 1413017856,
"server_location" : [-77.0367, 38.8951],
"client_location" : [-75.9534, 41.2973]
}
/* 6 */
{
"_id" : 1412398078,
"server_location" : [-77.0367, 38.8951],
"client_location" : [-76.0341, 41.1838]
}
我不明白为什么在 map-reduce 期间找不到这些。有人吗?
编辑 2
顺便说一句,当我将 $where
子句的条件更改为 this.server_location[0] == -77.8586 || this.server_location[0] == -77.6114
我得到了 50 个结果,而不是 map 函数打印的 7 个。奇怪的是,map-reduce 打印的 7 个结果是查询找到的 50 个结果中的前 7 个结果。
我迷路了
编辑 3
我想我知道问题出在哪里了。似乎 map-reduce 只提供前 100 条记录。问题是下一步是什么?
最佳答案
明白了:
Use limit() to specify a maximum number of points to return (a default limit of 100 applies if unspecified):
形成geospacial indexing页面。
问题是您的 $near
过滤,默认情况下它只返回前 100 个结果。要解决这个问题,您必须为查询指定一个限制。我不确定这是否与 map-reduce 语句兼容。你可以试试:
db.static.mapReduce(...).limit(500)
看看这是否会给您带来不同的结果。
关于mongodb - mongo 上的这个 map-reduce 查询有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9896349/
我在 mongo 中有一个查询,看起来像 db.Table_Name.group({ "key": { "Camp": true }, "initial": { "Clicks": 0 }
这是一个示例查询: db.readings.find( {"_id.s": ISODate("2012-11-01T00:05:00Z") }).count() 查询在 mongo shell 中工作
我正在使用 mongo 模板查询基于状态和邮政编码的文档,这是使用以下标准和查询方法实现的: List modelClass = null; Criteria criteria = new Crite
目前,我有一个旧版本的 mongo,即 2.6 在我的系统上运行。我的网站已经投入生产,并且拥有大量客户数据。我正在计划升级到 mongo 3.2。 所以,我的问题是 mongo v3.2 的 mon
我构建了一个 MongoDB。我想通过某些分组进行聚合。我找到了 document ,这将为我做到这一点。一切正常,但确定limitations指出: 管道的输出只能包含 16 兆字节。如果你的结果s
我无法连接到 MongoDB .在 Ubuntu 中它可以工作,但我在 CentOS 工作现在。这是错误信息: MongoDB shell version: 2.4.2 connecting to:
我试图使用mongo运行最简单的mongo-express和docker-compose容器。我遇到了许多错误,这些错误将在以后解释。 我尝试了以下docker-compose配置: 1。 versi
我有一个 mongo 查询,如下所示。 db.Course.find( { $and: [{courseCallNo: {$in : [/^ssoapicall1$/i]} }, {clientId
我想知道为什么我会收到以下 php 通知: ( ! ) Notice: Mongo::__construct(): parsing servers in C:\htdocs\multishop\lib
(问题灵感来自this one) 给定一个数据集: db.mycollection.insert([ {a:1, b:2, c:3}, {a:1, b:3, c:4}, {a:0, b:1
如果我已经使用 PECL 成功安装了 mongoDB,还需要获取 debian 软件包“php5-mongo”吗?有什么不同?(这个问题应该迁移吗?) 最佳答案 区别与从 CPAN 或 debian(
Mongo 一天前还运行良好。然后今天早上我起床并尝试打开我得到这个: MongoDB shell version: 2.6.4 2015-01-06T11:10:54.142-0500 SE
我正在尝试使用 C# Mongo 驱动程序将文件上传到 Mongo Atlas。但我不明白如何连接类 MongoServerSettings。我试过这个: private static MongoSe
我有两个版本的 mongodb,2.4.3 和 2.6.0。我可以在不同的端口上启动这两个版本,但是在使用 ./mongos 运行它时出现错误: BadValue error: no args for
我需要在 不 关闭的情况下进行分片,或者在端口 27017 中重启现有的 mongo 实例。 我尝试了以下操作,(当默认端口正在运行和 mongo 实例时) mongod --shardsvr --d
在无意中升级了 mongodb 包(3.4.9 -> 3.6.1)后,有没有办法升级 mongo 数据库? 根据 mongo 文档,作为 prerequisite在升级过程中,featureCompa
我正在使用 Sails 0.12.3 和 mongo 3.2.7 这是我的 config/connections.js。 mongo: { adapter: 'sails-mongo', host
我正在使用 mongodb 构建一个基本的搜索引擎,我已经验证了基本查询在 mongo shell 中的工作。不过,我不太明白如何将其翻译成 PHP。 输入字符串中的空格表示“和”运算符和 |或管道字
我有一个用 @Document 注释的 Mongo 集合,我希望能够从字符串 (JSON) 中获取该 Java 对象,因为我们正在将这些类作为字符串插入队列。 Spring-Data-Mongo 中是
我正在使用 Linux Debian 9。我已经安装了 JDK 1.8。我使用的maven版本是3.6,springboot的版本是2.1。 mongodb版本是3.6。 下面是我试图保存在 mong
我是一名优秀的程序员,十分优秀!