Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8548489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:30:29+00:00 2026-06-11T13:30:29+00:00

The MongoDB sorting functions are pretty neato. Can you use them on objects and/or

  • 0

The MongoDB sorting functions are pretty neato. Can you use them on objects and/or arrays that have nothing to do with the database itself?

var mongo       = require('mongodb'),
    Server      = mongo.Server,
    Db          = mongo.Db,
    sortingFun  = mongo.internalSortFilterFunction(); // By the miracle of imagination, this is a made-up line.

There is, for example, this awesome little node project called sift: MongoDB inspired array filtering. But there are more similar tools, different opinions, and projects merging and disappearing.

Considering it’s popularity, MongoDB is quite probably gonna hang around. For that reason, plus the added bonus of being exactly similar instead of pretty similar, I was wondering if a specific object/model/function within node-mongodb could be linked from the require('mongodb') specifically for using the sorting and filtering functions on custom objects/arrays.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T13:30:31+00:00Added an answer on June 11, 2026 at 1:30 pm

    The sorting is done in the mongo server, not the client. It’s also not particularily fast — big collections should be pre-sorted, but that’s another issue.

    The mongo server is afaik written in C++ and uses custom types, separate from the JS engine, called BSON.

    So if there is no sort implementation on the client for javascript, which would be an absurd feature, you can’t use server sort.

    Edit: If you really really want to use the sort, performance be damned, you could insert js objects into the DB, effectively converting them to BSON in mongo collections. Then sort it and pull it from the DB. Indexes etc will need to be recreated for every call to that function. Mongodb also refuses to sort for big collections sans index (limit being somewhere around 1000 I believe)

    PS. I haven’t read the source. I can’t imagine a JS realtime, indexless sort that matches the speed of MongoDB’s sort esp. when distributed (sharded). But you can write node.js modules in C++, and if BSON is similar enough to V8 JS objects (wouldn’t think so), you might be able to port it. I wouldn’t go down that road because it’s probably not going to be a big speed increase compared to reimplementing it in JS, a reimplementation which would be a lot easier to create and maintain.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Mongodb, you can write queries that include multiple attributes of objects and even
in MongoDb I can pass a predicate to an queryable instance for example DataBase.GetCollection<BsonDocument>(entity)
In MongoDB, a field can have multiple values (an array of values). Each of
In MongoDB, I have a document with a field called ClockInTime that was imported
I have a sorted (Mongodb) collection of objects: {_id: ObjectId(...), person: Homer, order: 1},
MongoDB has a very nice Geospatial Indexing feature. How can I use it in
My MongoDB collection has documents that can each contain an array of child documents.
In MongoDB you have a lot of helper methods that do all the basic
MongoDB has support for atomic updates. I.e. I can be sure that when a
Mongodb Database: {thread: abc, message: hjhjh, Date: (2010,4,5,0,0,0)} {thread: abc, message: hjhjh, Date: (2009,3,5,0,0,0)}

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.