louischatriot / nedb

The JavaScript Database, for Node.js, nw.js, electron and the browser
MIT License
13.46k stars 1.03k forks source link

Error: Cannot create a string longer than 0x1fffffe8 characters #691

Open bogere opened 2 years ago

bogere commented 2 years ago

I have been using the nedb for a good time but now I am getting funny errors after performing a test of million of records.. which were inserted successfully. But when I try to retrieve the records using db.find(), I get this error.

send this error to reporter Error: Cannot create a string longer than 0x1fffffe8 characters
    at Object.slice (buffer.js:573:37)
    at Buffer.toString (buffer.js:770:14)
    at FSReqCallback.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:56:23) {
  code: 'ERR_STRING_TOO_LONG'
}

Environment Window 10 Pro 64 bit... I was doing the test in the electron app but under the development conditions Expected results I expect it to find the records even if it is slower.

This is sample code for performance test

function performanceNeDBTest(){

    return new Promise((resolve,reject)=>{

      for (let i = 0; i < 1000000; i++) { // 1 million sale records being inserted      
        const newSale  = {
          prod_name: "PANGA STRAIGHT 18''",
          retail_price: 7000,
          costPrice: 5416,
          sales_qty: 3,
          who_sold: 'gerald',
          batchCode: null,
          customerId: 'TA2IEQW81ouTi07J',
          paymentOption: 'cash',
          depositAmount: 0,
          shopId: 'EB2I1OZYQHW',
          soldAt: new Date(),
          synced: false,
          closed: false
        }
          salesDB.insert(newSale, (err, newDoc)=>{
              console.log('Added sale record', i )
              if (i === (1000000-1) ) {
                  console.log("==================== DONE WITH BALLISTIC TEST ======>")
                  resolve("Completed the BALLISTIC NEDB SALES INSERTION")
              }
          })

      }

    })
  }
yeya commented 2 years ago

Solved by @seald here