node.js - Moongoose sort by parseFloat(String) -



node.js - Moongoose sort by parseFloat(String) -

i want sort query result float value. value stored in mongodb type string,can parse string float , sort dynamically? complex sort.

the next parts of schema , sort code:

schema:

var scenicspotschema = new schema({ ... detail_info: { ... overall_rating: string, ... }, });

sort function:

scenicspot.find({'name': new regexp(req.query.keyword)}, ) .sort('-detail_info.overall_rating') .skip(pagesize * pagenumber) .limit(pagesize) .exec(function (err, scenicspots) { if (err) { callback(err); } else { callback(null, scenicspots); } });

any kind of help , advice appreciated. :)

.sort mongoose not back upwards converting info type. see: http://mongoosejs.com/docs/api.html#query_query-sort

it take column names , order.

there 2 path acheive goal:

use mapreduce in mongo, first convert type, , sort retrieve info database, , sort in node.js program.

but both terrible , ugly

if wanna sort string column parse float. action scan info in collection, , can not utilize index. it's very slow action.

so think fastest , right operation convert string column float in mongodb database. , can utilize normal .sort('-detail_info.overall_rating') things done.

node.js mongodb sorting mongoose

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -