Skip to content

Instantly share code, notes, and snippets.

@arifmahmudrana
Last active December 30, 2020 06:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arifmahmudrana/36d83db9913e1126af052c5d3a8a12f3 to your computer and use it in GitHub Desktop.
Save arifmahmudrana/36d83db9913e1126af052c5d3a8a12f3 to your computer and use it in GitHub Desktop.
MongoDB sample queries
db.getCollection('search_params')
.find({ propertyCode: /R.+/ })
.sort({ propertyCode: -1 })
db.getCollection('search_params').aggregate([
{
$match: {
propertyCode: /^R.+$/,
},
},
{ $group: { _id: '$propertyCode', count: { $sum: 1 } } },
{
$sort: { count: -1 },
},
{ $limit: 10 },
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment