MongoDB数据集:对未减少或脚本有问题

MongoDB数据集:对未减少或脚本有问题,mongodb,mapreduce,dataset,Mongodb,Mapreduce,Dataset,我是编程和mongoDB的新手,在学习的过程中,我正在尝试使用mongoDB。到目前为止,我已经将csv转换为json,并使用compass将其导入mongoDB 在compass中,数据现在如下所示: _id :5bc4e11789f799178470be53 slug :"bitcoin" symbol :"BTC" name :"Bitcoin" date :"2013-04-28" ranknow :"1" op

我是编程和mongoDB的新手,在学习的过程中,我正在尝试使用mongoDB。到目前为止,我已经将csv转换为json,并使用compass将其导入mongoDB

在compass中,数据现在如下所示:

_id     :5bc4e11789f799178470be53
    slug    :"bitcoin"
    symbol  :"BTC"
    name    :"Bitcoin"
    date    :"2013-04-28"
    ranknow :"1"
    open    :"135.3"
    high    :"135.98"
    low     :"132.1"
    close   :"134.21"
    volume  :"0"
    market  :"1500520000"
    close_ratio :"0.5438"
    spread  :"3.88"
我将每个值作为索引添加如下,这是正确的过程吗,这样我就可以对数据运行mapreduce了

db.testmyCrypto.getIndexes() [ { “v”:2, “关键”:{ “_id”:1 }, “名称”:“id”, “ns”:“myCrypto.testmyCrypto” }, { “v”:2, “关键”:{ “鼻涕虫”:1 }, “名称”:“slug_1”, “ns”:“myCrypto.testmyCrypto” }, { “v”:2, “关键”:{ “符号”:2 }, “名称”:“符号2”, “ns”:“myCrypto.testmyCrypto” }, { “v”:2, “关键”:{ “姓名”:3 }, “名称”:“名称3”, “ns”:“myCrypto.testmyCrypto” }, { “v”:2, “关键”:{ “数据”:4 }, “名称”:“数据4”, “ns”:“myCrypto.testmyCrypto” }, { “v”:2, “关键”:{ “ranknow”:4 }, “名称”:“ranknow_4”, “ns”:“myCrypto.testmyCrypto” }, { “v”:2, “关键”:{ “ranknow”:5 }, “名称”:“ranknow_5”, “ns”:“myCrypto.testmyCrypto” }, { “v”:2, “关键”:{ “开放”:6 }, “名称”:“打开_6”, “ns”:“myCrypto.testmyCrypto” }, { “v”:2, “关键”:{ “高”:7 }, “名称”:“高_7”, “ns”:“myCrypto.testmyCrypto” }, { “v”:2, “关键”:{ “低”:8 }, “名称”:“低_8”, “ns”:“myCrypto.testmyCrypto” }, { “v”:2, “关键”:{ “卷”:9 }, “名称”:“第9卷”, “ns”:“myCrypto.testmyCrypto” }, { “v”:2, “关键”:{ “市场”:10 }, “名称”:“市场10”, “ns”:“myCrypto.testmyCrypto” }, { “v”:2, “关键”:{ “关闭比率”:11 }, “名称”:“接近比率11”, “ns”:“myCrypto.testmyCrypto” }, { “v”:2, “关键”:{ “价差”:13 }, “名称”:“spread_13”, “ns”:“myCrypto.testmyCrypto” } ]

我已经刮掉了上面的内容,现在我正在从地图的链接中做下面的事情。某人,这是正确的输出吗

> db.testmyCrypto.mapReduce(function() { emit( this.slug, this.symbol ); }, function(key, values) { return Array.sum( values ) },
... {
... query: { date:"2013-04-28" },
... out: "Date 04-28"
... }
... )
{
    "result" : "Date 04-28",
    "timeMillis" : 837,
    "counts" : {
        "input" : 0,
        "emit" : 0,
        "reduce" : 0,
        "output" : 0
    },
    "ok" : 1
}
我添加了“键值对”,但似乎无法从数据中获得任何信息

> db.testmyCrypto.mapReduce(function() { emit( this.slug, this.symbol, this.name, this.date, this.ranknow, this.open, this.high, this.low, this.close, this.volume, this.market, this.close_ratio, this.spread ); }, function(key, values) { return Array.sum( values ) }, { query: { slug:"bitcoin" }, out: "Date 04-28" } )
{ “结果”:“日期04-28”, “timeMillis”:816

>


如果您尝试对一些值求和,则它们需要为数字(当您将数据导入mongo时,请尝试设置值的类型)

此查询将返回按日期筛选的每个slug的打开值之和

另外,你可以用聚合做同样的事情

如果你有任何问题,请告诉我

"counts" : {
    "input" : 0,
    "emit" : 0,
    "reduce" : 0,
    "output" : 0
},
"ok" : 1 }
db.collectionName.mapReduce(
    function() { 
        emit( 
            this.slug, 
            this.open 
        ) 
    }, 
    function(keySlug, valueOpen) { 
        return Array.sum(valueOpen) 
    },
    {
        query: { date:"2013-04-28" },
        out: "Date 04-28"
    }
)