This file contains hidden or 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 listUsers = function () { | |
| db.adminCommand({"listDatabases":1}).databases.forEach(function(doc) { | |
| print(doc.name + ":"); | |
| db.getSiblingDB(doc.name).getCollection("system.users").find().forEach(printjson); | |
| }); | |
| } |
This file contains hidden or 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 convertTypes = function (sourceNS, targetNS) { | |
| var stringProps = ["field1", "field2", "field3", "field4"]; | |
| var numberIntProps = ["field5", "field6"]; | |
| var dateProps = ["field7"]; | |
| source = db.getSiblingDB(sourceNS.split(".")[0])[sourceNS.split(".")[1]]; | |
| target = db.getSiblingDB(targetNS.split(".")[0])[targetNS.split(".")[1]]; | |
| var convertToString = function (prop) { | |
| if (typeof prop === 'string') |
This file contains hidden or 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 checkAllVersions = function (verbose) { | |
| var equalOrLaterVersion = function (v1, v2) { | |
| return (v1[0] > v2[0]) || | |
| (v1[0] == v2[0] && v1[1] > v2[1]) || | |
| (v1[0] == v2[0] && v1[1] == v2[1] && v1[2] >= v2[2]); | |
| } | |
| var getHostInfo = function (info) { | |
| try { |
This file contains hidden or 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
| #!/usr/bin/env bash | |
| # Edit the following variables appropriately | |
| SOURCEDB="mydb" | |
| TARGETDB="test" | |
| TARGETCOLL="sp" | |
| mongodump -d $SOURCEDB -c system.profile -o /tmp | |
| mv /tmp/$SOURCEDB/system.profile.bson /tmp/$SOURCEDB/$TARGETCOLL.bson | |
| mongorestore --drop -d $TARGETDB -c $TARGETCOLL /tmp/$SOURCEDB/$TARGETCOLL.bson |
This file contains hidden or 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
| // Assuming that sp the name of collection that's a copy of the system.profile collection, | |
| // the following code tags each document containing a query field with a queryHash value | |
| // based on the shape of the query and orderby (or sort). There's also a sample aggregation | |
| // pipeline that uses the new queryHash field. E.g. tagQueries("sp") or aggQueries("sp") | |
| var tagQueries = function (sp) { | |
| var queryToHash = function (doc) { | |
| var props = new Array(); | |
| // Recursively walk the query or sort document pushing fieldnames onto the props array. |
This file contains hidden or 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
| map = function () { | |
| totalDocs++; | |
| var C = function(node, prefix) { | |
| for (var inner_prop in node) { | |
| if (typeof node[inner_prop] == 'object') { | |
| emit(prefix + "." + inner_prop, 1); | |
| result = C(node[inner_prop], prop + "." + inner_prop); | |
| } | |
| else if (node.hasOwnProperty(inner_prop) && inner_prop != 'str'){ | |
| emit(prefix + "." + inner_prop, 1); |
This file contains hidden or 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 diffIndexes = function() { | |
| var replsetInfo = new Array(); | |
| var maxIterations = 0; | |
| rs.slaveOk(); | |
| rs.status().members.forEach(function(member) { | |
| if (member.stateStr == "PRIMARY" || member.stateStr == "SECONDARY") { | |
| var memberInfo = { | |
| name : member.name, | |
| cursor : 0, |
This file contains hidden or 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 printDupValidKeys = function() { | |
| db.adminCommand({"listDatabases":1}).databases.forEach( | |
| function(sdb) { | |
| print(sdb.name); | |
| try { | |
| dupes=db.getSiblingDB(sdb.name).StringLookup.aggregate( | |
| [ { $group: { | |
| "_id" : "$Value", | |
| "c": { "$sum" : 1 } } }, | |
| { $match : { |
This file contains hidden or 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 printAllIndexes = function() { | |
| rs.slaveOk() | |
| db.adminCommand({"listDatabases":1}).databases.forEach(function(doc){ | |
| print(doc.name); | |
| db.getSiblingDB(doc.name).system.indexes.find().sort({ns:1,name:1}).forEach(printjson); | |
| }); | |
| } |
This file contains hidden or 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 validateCollections = function(dbname) { | |
| var vdb = db.getMongo().getDB(dbname); | |
| vdb.getCollectionNames().forEach(function(coll) { | |
| printjson(vdb[coll].validate(true)); | |
| }); | |
| } |
NewerOlder