0
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 } 

我想在“值”字段中使用 collectionname 而不是 null 。

4

0 回答 0