Tag: sorting

按照子对象属性值sorting对象属性

我有一个解决scheme,但我不是很满意的实施。 希望在这里得到一些反馈,如何改进,无论是sorting或数据结构。 我想要做的是通过其一个子对象属性值为对象的属性sorting。 我的数据结构如下: 对象叫冠军: { '32': { played: 1, image: 'Amumu.png', won: 0 }, '60': { played: 5, image: 'Elise.png', won: 3 }, '79': { played: 4, image: 'Gragas.png', won: 3 }, '245': { played: 1, image: 'Ekko.png', won: 0 }, '254': { played: 2, image: 'Vi.png', won: 1 }, '421': { played: 2, […]

下载并修剪aerospike udf列表

我尝试删除和修剪列表以build立分页系统 local function createMap(postId, paramDate) local m = map { id = postId, date = paramDate }; return m; end function get(rec, binName, from, to) if aerospike:exists(rec) then local l = rec[binName] if (l == nil) then return nil else local length = #l; if (length <= 10 and to <=10) then return l; elseif […]

使用从模型的远程方法中查找时的环回顺序filter,错误:

在远程方法中查找时,我正在用一个简单的sortingfilter很难: /** * This remote method exposes the meals history from the current logged in user */ Meal.listMeals = function(req, res, cb) { Meal.find({ where: {patientId: req.accessToken.userId}, order: {mealDate: 'DESC'} }, cb); }; Meal.remoteMethod('listMeals', { returns: {arg: 'meals', type: 'array'}, http: {path:'/list-meals', verb: 'get'}, accepts: [ {arg: 'req', type: 'object', http: {source: 'req'}}, {arg: 'res', […]

Mongoose传递嵌套的sorting对象进行查询

我有以下查询,作为一个硬编码的string传递作品: router.get( '/rank/:round/', ( req, res, next ) => { let query = { "score.0.r1" : -1}; Team.find( {} ) .sort( query ) .then( teams => { return res.json( teams ); } ).catch( next ); } ); 但是,当我尝试通过我的路线参数:round像这样的:round : let query = { "score.0.r" + req.params.round : -1}; 它不起作用(它返回一个未sorting的列表)。 我也试过了: let sort = "score.0['r" + […]

按名称,date和层次sorting列表

我想按以下顺序对以下列表进行sorting: 首先由没有任何父母的对象 然后按名称 按年份 按月份 相关对象应该直接在标准之后(2-4)。 所以我想要实现的基本上是一个扁平化的树形结构。 这是我到现在为止,但无法弄清楚如何实现父母的关系。 function monthYearCheck(a, b) { if(a.year < b.year) { return -1; } else if(a.year > b.year) { return 1; } else { if(a.month < b.month) { return -1; } else if(a.month > b.month) { return 1; } else { return 0; } } } var sortedArray = nonSortedArray.sort(function […]

mongoose – 如何sorting多种标准的人口

我正在尝试对group.name首先填充“group.name”的angular色文档进行sorting,然后再对role.name进行sorting return this.find(query, { _group: 1, name: 1, _id:0 } ) .populate('_group', 'name -_id') .sort({ '_group.name': 1, name: 1 }) 但它不能按预期工作,我只能在role.name上sorting ROLES:[ {"name":"NewRole"}, {"name":"NewRoleInGroup","_group":{"name":"GroupA"}}, {"_group":{"name":"GroupA"},"name":"admin"}, {"_group":{"name":"GroupA"},"name":"employee"}, {"_group":{"name":"GroupB"},"name":"employee"}, {"_group":{"name":"GroupC"},"name":"employee"}, {"_group":{"name":"GroupA"},"name":"manager"}, {"_group":{"name":"GroupB"},"name":"manager"}, {"name":"visitor"} ] 我想得到的是: ROLES:[ // NO GROUP {"name":"NewRole"}, {"name":"visitor"}. // GroupA {"_group":{"name":"GroupA"},"name":"admin"}, {"_group":{"name":"GroupA"},"name":"employee"}, {"_group":{"name":"GroupA"},"name":"manager"}, {"name":"NewRoleInGroup","_group":{"name":"GroupA"}}, // GroupB {"_group":{"name":"GroupB"},"name":"employee"}, {"_group":{"name":"GroupB"},"name":"manager"}, // GroupC {"_group":{"name":"GroupC"},"name":"employee"} ] 感谢您的反馈 更新根据@Talha评论: […]

按浮点值sorting数组

我有一些麻烦sorting一个浮点值的数组。 我search了networking,我知道我必须使用比较函数,但是我有理解这个概念的问题。 我正在使用这个代码来读取一个xlxs文件,并将我需要的值推到一个更简单的数组。 我需要通过top2box键的值sorting这个数组,所以最高的值是键0。 这是我目前的代码 // data is an array of arrays, lets loop through it to sort. The array contains each row of my xlxs file. var hon = [] //array that will hold the sorted entries from the excel file for(var i = 0; i < data.length; i++) { // we dont want […]

与Mongosorting

我正在尝试对我的MongoDB数据进行sorting。 我有一个下面显示的租赁架构,其中包括一个“精选”项目。 如果特色项目设置为true(用户可以在他们的最后执行此操作),我希望特色项目显示在租赁的其余部分之上。 换句话说,我需要将mongo数据的特征= truesorting到顶端。 我如何改变我的代码来做到这一点? 这是我的租赁架构: var rentalsSchema = new mongoose.Schema({ featured: { type: Boolean, default: false }, Title: String, }); 这是我到目前为止所尝试的(并且不工作)。 router.get('/rentals', function(req, res) { db.collection('rentals').find().sort({ featured: 1 }).toArray(function(err, items) { }); });

数组中的特征项

我有一个包含在variables“foundListings.currentimages”下面的图像链接数组。 在前端,用户可以检查“特色”框以select要显示的图像。 所有这一切运作良好。 但是,我不知道如何将foundListings.currentimages下的图像移动到数组的前面。 (如果它在arrays的前面,它的特色。) 我将如何更改代码foundListings.currentimages.splice(index2, 1); 不从数组中删除项目,而是把它放在数组中? 谢谢你的帮助! 🙂 // SELECTING FEATURED IMAGE // if any images have been selected for feature, — add it to front of array if(req.body.feature && req.body.feature.length) { for(var i = 0; i < req.body.feature.length; i++) { var index2 = foundListings.currentimages.indexOf(req.body.feature[i]); foundListings.currentimages.splice(index2, 1); } } foundListings.save(); }

MongoDB按节点mongodb-nativesorting

我想sortingMongo查询的结果。 从这里我发现我可以这样做,例如: collection.find().sort( { name: 1 } ).limit( 5 ) 因为我不想按名称sorting,而是按请求指定: var query = require('url').parse(req.url, true).query; var n = parseInt(query.limit); var f = String(query.field); var dir = query.direction; collection.find().sort({f: dir}).limit(n) 问题是,它按“f”sorting,而不是variablesf的值。 我怎样才能sorting存储在f?