1

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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.