This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getStorageDetails() { | |
var db = this.db.getSiblingDB("admin"); | |
var totalIndexSize = 0, | |
totalStorageSize = 0, | |
totalDataSize = 0, | |
formatSize = 1024 * 1024 * 1024; | |
// List the databases | |
var dbs = db.runCommand({ listDatabases: 1 }).databases; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var colls = db.getCollectionNames(); | |
var ret = []; | |
colls.forEach(function(coll) { | |
var indexes = db.getCollection(coll).getIndexes(); | |
var len = indexes.length | |
if (len >= 10) { | |
ret.push({ "name": coll, "length": len, "data": indexes}); | |
} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getStorageDetails() { | |
var db = this.db.getSiblingDB("admin"); | |
var totalIndexSize = 0, | |
totalStorageSize = 0, | |
totalDataSize = 0, | |
formatSize = 1024 * 1024 * 1024; | |
// List the databases | |
var dbs = db.runCommand({ listDatabases: 1 }).databases; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.currentOp(true).inprog.reduce( | |
(accumulator, connection) => { | |
ipaddress = connection.client ? connection.client.split(":")[0] : "Internal"; | |
accumulator[ipaddress] = (accumulator[ipaddress] || 0) + 1; | |
accumulator["TOTAL_CONNECTION_COUNT"]++; | |
return accumulator; | |
}, | |
{ TOTAL_CONNECTION_COUNT: 0 } | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const MongoClient = require("mongodb").MongoClient; | |
const { LoremIpsum } = require("lorem-ipsum"); | |
const cluster = require('cluster'); | |
const MONGOURI = "MONGO_URI"; | |
const DB = "test_db"; | |
const COLL = "test_coll"; | |
/* Lorem Ipsum Generator */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var colls = db.getCollectionNames(); | |
var ret = []; | |
colls.forEach(function(coll) { | |
var stats = db.getCollection(coll).stats(); | |
ret.push({ "name": coll, "stats": stats}); | |
}) | |
printjson(ret) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getStorageDetails() { | |
var db = this.db.getSiblingDB("admin"); | |
var totalIndexSize = 0, | |
totalStorageSize = 0, | |
totalDataSize = 0, | |
formatSize = 1024 * 1024 * 1024; | |
// List the databases | |
var dbs = db.runCommand({ listDatabases: 1 }); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Simple demonstration using MongoDB Client-Side Field Level Encryption (local key version) | |
Requires Community or (preferrably) Enterprise Shell and a MongoDB 4.2+ database | |
Local, stand-alone, or Atlas MongoDB will all work. | |
To use this, just open Mongo shell, with this file, e.g.: | |
mongo --nodb --shell hello_world_shell_local.js | |
# For a self-signed cert: mongo --tls --tlsCAFile /opt/mongodb/certs/ca.pem --shell hello_world_shell_local.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var colls = db.getCollectionNames(); | |
var ret = []; | |
colls.forEach(function(coll) { | |
var indexes = db.getCollection(coll).getIndexes(); | |
var len = indexes.length | |
ret.push({ "name": coll, "length": len }); | |
}) | |
printjson(ret) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var objectIdFromDate = function (date) { | |
return Math.floor(date.getTime() / 1000).toString(16) + "0000000000000000"; | |
}; | |
var dateFromObjectId = function (objectId) { | |
return new Date(parseInt(objectId.substring(0, 8), 16) * 1000); | |
}; | |
OlderNewer