Snippets Collections
db.setProfilingLevel(0)
db.system.profile.drop()
db.setProfilingLevel(2)
String.prototype.interpolate = function(params) {
  const names = Object.keys(params);
  const vals = Object.values(params);
  return new Function(...names, `return \`${this}\`;`)(...vals);
}

const template = 'Example text: ${text}';
const result = template.interpolate({
  text: 'Foo Boo'
});
console.log(result);
db.getCollection('Transaction').aggregate([
    {"$group" : { "_id": "$transactionNo", "count": { "$sum": 1 }, "ids":{"$push":"$_id"} } },
    {"$match": {"_id" :{ "$ne" : null } , "count" : {"$gt": 1} } }
])
db.getCollection('AccountSummary').createIndex({txDate: NumberInt(1)});
db.getCollection('AccountSummary').createIndex({jobId:NumberInt(1)});
db.getCollection('AccountSummary').createIndex({userId:NumberInt(1)});
db.getCollection('AccountSummary').createIndex({isActive:NumberInt(1)});
db.Foo.aggregate(
  {$unwind: "$bars"},
  {$lookup: {
    from:"bar",
    localField: "bars",
    foreignField: "_id",
    as: "bar"

   }},
   {$match: {
    "bar.testprop": true
   }}
)
star

Wed Jun 16 2021 15:36:20 GMT+0000 (UTC)

#mongoshell
star

Mon Jan 11 2021 06:22:04 GMT+0000 (UTC)

#typescript #mongoshell
star

Mon Nov 02 2020 13:14:31 GMT+0000 (UTC) https://stackoverflow.com/questions/26984799/find-duplicate-records-in-mongodb

#mongoshell
star

Wed Aug 19 2020 06:27:09 GMT+0000 (UTC) https://docs.mongodb.com/manual/tutorial/manage-indexes/

#mongoshell
star

Thu May 21 2020 18:26:52 GMT+0000 (UTC) https://stackoverflow.com/questions/9621928/how-do-i-query-referenced-objects-in-mongodb

#javascript #mongoshell

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension