收集数组Ruby中每个元素的0索引

时间:2016-06-30 18:30:19

标签: ruby-on-rails arrays ruby list

我有一个数组array = [[53,600],[9,89],[56,9],...[4,67]],我有兴趣创建一个新的list,只包含array中每个元素的第一个条目。所以,我想要的输出是list = [53,9,56,....,4]。我该怎么做?

1 个答案:

答案 0 :(得分:5)

db.getCollection('yourCollection').aggregate([ { $unwind: { path: "$detailLine" } }, { $project: { allowedAmount: "$detailLine.value.detailLineCharges.allowedAmount" } }, { $group: { _id: "x", details: { $push: "$allowedAmount" } } } ]) { "_id" : "x", "details" : [ { "amount" : "11111", "reasonCode" : "aaaah" }, { "amount" : "22222", "reasonCode" : "BBBB" } ] } SymbolToProc 一起使用:

map