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 } 

I want collectionname in the "value" field instead of null .

BenMorel
  • 34,448
  • 50
  • 182
  • 322
user2609099
  • 27
  • 1
  • 6
  • Change your function to store it. I don't get your problem. I also don't understand what you're trying to accomplish or why you're trying to use mapreduce in this way. – WiredPrairie Aug 13 '13 at 20:53
  • I am trying to get all the fields in the database from each colllection.I am able to get field names but not able to get collection name of that filed.so I want filed names with collection name in the output. – user2609099 Aug 13 '13 at 21:35
  • Store the results for each database in a different `out`. – WiredPrairie Aug 14 '13 at 00:58

0 Answers0