Mongodb sort by number Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!MongoDB vs. CassandraHow to query MongoDB with “like”?Update MongoDB field using value of another fieldMongoDB relationships: embed or reference?How do I drop a MongoDB database from the command line?Using .sort with PyMongoHow does MongoDB sort records when no sort order is specified?“Large data” work flows using pandasmaximum limit for MongoDB 2.6 sort querySorting on index of array mongodb

Is there any word for a place full of confusion?

Should I follow up with an employee I believe overracted to a mistake I made?

Why does the remaining Rebel fleet at the end of Rogue One seem dramatically larger than the one in A New Hope?

Central Vacuuming: Is it worth it, and how does it compare to normal vacuuming?

How could we fake a moon landing now?

Illegal assignment from sObject to Id

What does it mean that physics no longer uses mechanical models to describe phenomena?

The code below, is it ill-formed NDR or is it well formed?

Do I really need to have a message in a novel to appeal to readers?

Hangman Game with C++

What was the first language to use conditional keywords?

ArcGIS Pro Python arcpy.CreatePersonalGDB_management

How does light 'choose' between wave and particle behaviour?

How can I reduce the gap between left and right of cdot with a macro?

Can anything be seen from the center of the Boötes void? How dark would it be?

Drawing without replacement: why is the order of draw irrelevant?

Why wasn't DOSKEY integrated with COMMAND.COM?

Why does it sometimes sound good to play a grace note as a lead in to a note in a melody?

Can a new player join a group only when a new campaign starts?

Chebyshev inequality in terms of RMS

What do you call the main part of a joke?

Maximum summed subsequences with non-adjacent items

Disembodied hand growing fangs

Why should I vote and accept answers?



Mongodb sort by number



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!MongoDB vs. CassandraHow to query MongoDB with “like”?Update MongoDB field using value of another fieldMongoDB relationships: embed or reference?How do I drop a MongoDB database from the command line?Using .sort with PyMongoHow does MongoDB sort records when no sort order is specified?“Large data” work flows using pandasmaximum limit for MongoDB 2.6 sort querySorting on index of array mongodb



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I'm trying to sort by a field that includes numbers and when doing .sort(title: 1) it will return results like 1,10,11,12,2,3,4. I would like to have it return like 1,2,3,4,10,11,12, is this possible directly from mongo?










share|improve this question




























    1















    I'm trying to sort by a field that includes numbers and when doing .sort(title: 1) it will return results like 1,10,11,12,2,3,4. I would like to have it return like 1,2,3,4,10,11,12, is this possible directly from mongo?










    share|improve this question
























      1












      1








      1








      I'm trying to sort by a field that includes numbers and when doing .sort(title: 1) it will return results like 1,10,11,12,2,3,4. I would like to have it return like 1,2,3,4,10,11,12, is this possible directly from mongo?










      share|improve this question














      I'm trying to sort by a field that includes numbers and when doing .sort(title: 1) it will return results like 1,10,11,12,2,3,4. I would like to have it return like 1,2,3,4,10,11,12, is this possible directly from mongo?







      mongodb






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jun 10 '14 at 19:12









      dzmdzm

      9,44336107196




      9,44336107196






















          3 Answers
          3






          active

          oldest

          votes


















          3














          You are probably sorting your documents on a field that contains strings, not numbers. MongoDB sorts numbers in their natural order and strings in their alphabetical order.



          You will need to convert values of your title field to integers to get natural ordering.



          This is an example result from sorting a collection on field a that contains strings and integers.



           _id: ObjectId("53975b47bff015b5a400097b"), a: 1 
          _id: ObjectId("53975b74bff015c524000864"), a: 9
          _id: ObjectId("53975b5d74c5e23516000919"), a: 10
          _id: ObjectId("53975b5d74c5e23516000200"), a: "1"
          _id: ObjectId("53975b8ebff01545bd0006b4"), a: "10"
          _id: ObjectId("53975b9e32105bb92f0007fd"), a: "9"





          share|improve this answer






























            0














            This can help You to sort in ascending order :-
            db.collectionName.find().sort(sortingParameter: 1).collation(locale: "en_US", numericOrdering: true)



            :)






            share|improve this answer






























              0














              router.get('/projectstatus/list', (req, res) => 
              Addstatus
              .find()
              .sort(order: 1)
              .collation(locale: "en_US", numericOrdering: true)
              .then(addstatus => res.json(addstatus) )
              .catch(err => console.log("------------------Data is not found----------------n") );;
              );





              share|improve this answer




















              • 1





                Welcome to stackoverflow. In addition to the answer you've provided, please consider providing a brief explanation of why and how this fixes the issue.

                – jtate
                Mar 8 at 22:09











              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f24149105%2fmongodb-sort-by-number%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              3














              You are probably sorting your documents on a field that contains strings, not numbers. MongoDB sorts numbers in their natural order and strings in their alphabetical order.



              You will need to convert values of your title field to integers to get natural ordering.



              This is an example result from sorting a collection on field a that contains strings and integers.



               _id: ObjectId("53975b47bff015b5a400097b"), a: 1 
              _id: ObjectId("53975b74bff015c524000864"), a: 9
              _id: ObjectId("53975b5d74c5e23516000919"), a: 10
              _id: ObjectId("53975b5d74c5e23516000200"), a: "1"
              _id: ObjectId("53975b8ebff01545bd0006b4"), a: "10"
              _id: ObjectId("53975b9e32105bb92f0007fd"), a: "9"





              share|improve this answer



























                3














                You are probably sorting your documents on a field that contains strings, not numbers. MongoDB sorts numbers in their natural order and strings in their alphabetical order.



                You will need to convert values of your title field to integers to get natural ordering.



                This is an example result from sorting a collection on field a that contains strings and integers.



                 _id: ObjectId("53975b47bff015b5a400097b"), a: 1 
                _id: ObjectId("53975b74bff015c524000864"), a: 9
                _id: ObjectId("53975b5d74c5e23516000919"), a: 10
                _id: ObjectId("53975b5d74c5e23516000200"), a: "1"
                _id: ObjectId("53975b8ebff01545bd0006b4"), a: "10"
                _id: ObjectId("53975b9e32105bb92f0007fd"), a: "9"





                share|improve this answer

























                  3












                  3








                  3







                  You are probably sorting your documents on a field that contains strings, not numbers. MongoDB sorts numbers in their natural order and strings in their alphabetical order.



                  You will need to convert values of your title field to integers to get natural ordering.



                  This is an example result from sorting a collection on field a that contains strings and integers.



                   _id: ObjectId("53975b47bff015b5a400097b"), a: 1 
                  _id: ObjectId("53975b74bff015c524000864"), a: 9
                  _id: ObjectId("53975b5d74c5e23516000919"), a: 10
                  _id: ObjectId("53975b5d74c5e23516000200"), a: "1"
                  _id: ObjectId("53975b8ebff01545bd0006b4"), a: "10"
                  _id: ObjectId("53975b9e32105bb92f0007fd"), a: "9"





                  share|improve this answer













                  You are probably sorting your documents on a field that contains strings, not numbers. MongoDB sorts numbers in their natural order and strings in their alphabetical order.



                  You will need to convert values of your title field to integers to get natural ordering.



                  This is an example result from sorting a collection on field a that contains strings and integers.



                   _id: ObjectId("53975b47bff015b5a400097b"), a: 1 
                  _id: ObjectId("53975b74bff015c524000864"), a: 9
                  _id: ObjectId("53975b5d74c5e23516000919"), a: 10
                  _id: ObjectId("53975b5d74c5e23516000200"), a: "1"
                  _id: ObjectId("53975b8ebff01545bd0006b4"), a: "10"
                  _id: ObjectId("53975b9e32105bb92f0007fd"), a: "9"






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jun 10 '14 at 19:34









                  Christian PChristian P

                  9,28544864




                  9,28544864























                      0














                      This can help You to sort in ascending order :-
                      db.collectionName.find().sort(sortingParameter: 1).collation(locale: "en_US", numericOrdering: true)



                      :)






                      share|improve this answer



























                        0














                        This can help You to sort in ascending order :-
                        db.collectionName.find().sort(sortingParameter: 1).collation(locale: "en_US", numericOrdering: true)



                        :)






                        share|improve this answer

























                          0












                          0








                          0







                          This can help You to sort in ascending order :-
                          db.collectionName.find().sort(sortingParameter: 1).collation(locale: "en_US", numericOrdering: true)



                          :)






                          share|improve this answer













                          This can help You to sort in ascending order :-
                          db.collectionName.find().sort(sortingParameter: 1).collation(locale: "en_US", numericOrdering: true)



                          :)







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Feb 23 at 11:27









                          DeveshDevesh

                          394




                          394





















                              0














                              router.get('/projectstatus/list', (req, res) => 
                              Addstatus
                              .find()
                              .sort(order: 1)
                              .collation(locale: "en_US", numericOrdering: true)
                              .then(addstatus => res.json(addstatus) )
                              .catch(err => console.log("------------------Data is not found----------------n") );;
                              );





                              share|improve this answer




















                              • 1





                                Welcome to stackoverflow. In addition to the answer you've provided, please consider providing a brief explanation of why and how this fixes the issue.

                                – jtate
                                Mar 8 at 22:09















                              0














                              router.get('/projectstatus/list', (req, res) => 
                              Addstatus
                              .find()
                              .sort(order: 1)
                              .collation(locale: "en_US", numericOrdering: true)
                              .then(addstatus => res.json(addstatus) )
                              .catch(err => console.log("------------------Data is not found----------------n") );;
                              );





                              share|improve this answer




















                              • 1





                                Welcome to stackoverflow. In addition to the answer you've provided, please consider providing a brief explanation of why and how this fixes the issue.

                                – jtate
                                Mar 8 at 22:09













                              0












                              0








                              0







                              router.get('/projectstatus/list', (req, res) => 
                              Addstatus
                              .find()
                              .sort(order: 1)
                              .collation(locale: "en_US", numericOrdering: true)
                              .then(addstatus => res.json(addstatus) )
                              .catch(err => console.log("------------------Data is not found----------------n") );;
                              );





                              share|improve this answer















                              router.get('/projectstatus/list', (req, res) => 
                              Addstatus
                              .find()
                              .sort(order: 1)
                              .collation(locale: "en_US", numericOrdering: true)
                              .then(addstatus => res.json(addstatus) )
                              .catch(err => console.log("------------------Data is not found----------------n") );;
                              );






                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Mar 8 at 20:30









                              pzaenger

                              3,30011727




                              3,30011727










                              answered Mar 8 at 20:29









                              Vivek YadavVivek Yadav

                              11




                              11







                              • 1





                                Welcome to stackoverflow. In addition to the answer you've provided, please consider providing a brief explanation of why and how this fixes the issue.

                                – jtate
                                Mar 8 at 22:09












                              • 1





                                Welcome to stackoverflow. In addition to the answer you've provided, please consider providing a brief explanation of why and how this fixes the issue.

                                – jtate
                                Mar 8 at 22:09







                              1




                              1





                              Welcome to stackoverflow. In addition to the answer you've provided, please consider providing a brief explanation of why and how this fixes the issue.

                              – jtate
                              Mar 8 at 22:09





                              Welcome to stackoverflow. In addition to the answer you've provided, please consider providing a brief explanation of why and how this fixes the issue.

                              – jtate
                              Mar 8 at 22:09

















                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f24149105%2fmongodb-sort-by-number%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

                              Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

                              Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved