Home > Blockchain >  Add AllowDiskUse true to MongoDB aggregation in node.js?
Add AllowDiskUse true to MongoDB aggregation in node.js?

Time:09-18

This is my code that I want to execute in node.js but I am getting memory errors:

import { MongoClient } from 'mongodb';

const agg = [
  {
    '$group': {
      '_id': '$nine', 
      'count': {
        '$sum': 1
      }
    }
  }
];

const client = await MongoClient.connect(
  'mongodb srv here',
  { useNewUrlParser: true, useUnifiedTopology: true }
);
const coll = client.db('myDatabase').collection('myCollection');
const cursor = coll.aggregate(agg).allowDiskUse(true);
const result = await cursor.toArray();
console.log(result);
await client.close();

Where I can add AllowDiskUse True true in this?

CodePudding user response:

With the nodejs driver this is passed as the "options" parameter, like so:

const cursor = coll.aggregate(agg, { allowDiskUse: true})
  • Related