Jaffer Wilson
Jaffer Wilson

Reputation: 7273

Changing default path of the temp folder while using MongoDB

I have set MongoDB and am trying to perform aggregate functions on the MongoDB.

This is what I tried:

var ops = [];

db.tt.aggregate([
  { "$unwind": "$src" },
  { "$group": {
    "_id": { "$toLower": "$email" },
    "src": { "$addToSet": "$src" },
    "ids": { "$addToSet": "$_id" }
  }}
],
{
allowDiskUse:true
}).forEach(doc => {
  var id = doc.ids.shift();
  ops = [
    ...ops,
    {
      "deleteMany": {
        "filter": { "_id": { "$in": doc.ids } }
      }
    },
    { 
      "updateOne": { 
        "filter": { "_id": id },
        "update": { 
          "$set": { "email": doc._id },
          "$addToSet": { "src": { "$each": doc.src } }
        }
      }
    },
  ];

  if ( ops.length >= 500 ) {
    db.tt1.bulkWrite(ops);
    ops = [];
  }

});

But the problem is that allowDiskUse:true create _tmp folder to write temporary files. Now, space where my MongDB data is available in not compatible with the temp data. Hence I want to use the external storage for that purpose. Is there a way to specify the temp storage for the process?

Upvotes: 1

Views: 1180

Answers (1)

Wernfried Domscheit
Wernfried Domscheit

Reputation: 59523

The path name is fixed, but you can create a symbolic link for it, for example:

cd /var/lib/mongo/
mv _tmp /another-drive/mongo/
ln -s /another-drive/mongo/_tmp

Bear in mind, an external storage might be much slower than the internal disk.

Upvotes: 1

Related Questions