问题
var allCollections = db.getCollectionNames();
for (var i = 0; i < allCollections.length; ++i) {
var collectioname = allCollections[i];
if (collectioname === 'system.indexes')
continue;
db.runCommand(
{ "mapreduce" : collectioname, "map" : function()
{
for (var key in this) {
emit(key, null);
}
}, "reduce" : function(key, stuff) {
return null;
}, "out":mongo_test + "_keys"
}) }
output
{ "_id" : "_id", "value" : null }
{ "_id" : "collection_name", "value" : null }
{ "_id" : "database", "value" : null }
{ "_id" : "host", "value" : null }
{ "_id" : "port", "value" : null }
{ "_id" : "cardid", "value" : null }
{ "_id" : "ccard", "value" : null }
{ "_id" : "creditcardnum", "value" : null }
{ "_id" : "date", "value" : null }
{ "_id" : "value", "value" : null }
I want collectionname in the "value" field instead of null .
来源:https://stackoverflow.com/questions/18006980/how-to-add-collection-name-in-the-output-of-map-reduce-job-to-get-all-the-keys-i