如何根据mongodb记录在另一个数组中的位置对其进行排序

时间:2017-03-08 07:56:25

标签: javascript arrays node.js mongodb mongoose

我使用Mongoose查询MongoDB并获取记录以及填充的记录,但是我想对我收到的填充记录进行排序。

val df = spark.read.option("header",true).option("inferSchema","false").csv("C:/data.csv")
val columToKeep = df.columns.map(c => stddev(c).as(c))
val new_Data= df.select(columToKeep:_*)//issue here because name contains "."


  Row.Number,Poids,Age,Taille,0M.I,Hmean,Cooc.Param,Ldp.Param,Test.2,Classe.2
0,87,72,160,5,0.6993,2.9421,2.3745,3,4
1,54,70,163,5,0.6301,2.7273,2.2205,3,4
2,72,51,164,5,0.6551,2.9834,2.3993,3,4
3,75,74,170,5,0.6966,2.9654,2.3699,3,4
 column with constant variable 
 expected output
 OM.I,Test.2,Classe.2
5,3,4
5,3,4
5,3,4
5,3,4

并且,填充后看起来像

const record = Model.findOne({ '_id': '10b9ad30be4c3c0e98cf199q' });
{
  "_id" : 10b9ad30be4c3c0e98cf199q,
  "name" : "Hello World",
  "_order" : [ "28b802cd0588741258d01120", 28b802cd0588741258d01130"", "28b802cd0588741258d01140" ],
}

如何根据const record = Model.findOne({ '_id': '10b9ad30be4c3c0e98cf199q' }).populate('items'); { "_id" : 10b9ad30be4c3c0e98cf199q, "name" : "Hello World", "_order" : [ "28b802cd0588741258d01120", 28b802cd0588741258d01130"", "28b802cd0588741258d01140" ], "items" : [ { "_id" : 28b802cd0588741258d01140, name: "Games" }, { "_id" : 28b802cd0588741258d01120, name: "Movies" } { "_id" : 28b802cd0588741258d01130, name: "Science?" } ] } 字段中的items对填充的记录_id进行有效排序? 甚至是可能的,或者我必须在获取记录后在客户端/服务器中执行此操作。

0 个答案:

没有答案