A simple query to get random documents from the entire collection in stead of sorting.
DB.Model_Name.find( { }, { }, { sort: { something simple here } } );
A simple query to get random documents from the entire collection in stead of sorting.
DB.Model_Name.find( { }, { }, { sort: { something simple here } } );
Hi @Naw_Ing and welcome to the community forum.
If you wish to get a random document from the collection, you can make use of the $sample operator to get specified number of documents.
For example, if you wish to get only one random document, you can write your query as:
db.collection.aggregate([{ $sample: { size: 1 } }])
Please let us know if you have any further questions.
Best Regards
Aasawari