mongodb - eller optegnelser

, sort() metode, at dokumenter i mongodb, du skal bruge, sort() metode., sort(), metode accepterer et dokument, der indeholder listen over områder sammen med deres sortering.for at præcisere sortering for 1 og - 1, anvendes.1 is used for ascending order while -1 is used for descending order.,Syntax:,Basic syntax of ,sort(), method is as follows,>db.COLLECTION_NAME.find().sort({KEY:1}) ,Example,Consider the collection myycol has the following data, { "_id" : ObjectId(5983548781331adf45ec5), "title":"MongoDB Overview"} { "_id" : ObjectId(5983548781331adf45ec6), "title":"NoSQL Overview"} { "_id" : ObjectId(5983548781331adf45ec7), "title":"Tutorials Point Overview"} ,Following example will display the documents sorted by title in descending order.,>db.mycol.find({},{"title":1,_id:0}).sort({"title":-1}) {"title":"Tutorials Point Overview"} {"title":"NoSQL Overview"} {"title":"MongoDB Overview"}> ,Please note if you don't specify the sorting preference, then ,sort(), metode vil vise dokumenter i rækkefølge.



Previous:
Next Page: