Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Current topology does not support session

enter image description here

Hi,

I am getting error "Current topology does not support session" Plese refer attached image..

and code as

async function insertBooking(parking, aFunction) {
    const session = await BookingSchema.startSession().catch(error => {
        console.log(error);
    });

    try {
        session.startTransaction();
        let booking = new BookingSchema(parking)
        mongoose.startSession();
        booking.save(function (err, booking) {
            if (booking) {
               //code to be run
            }


        })
        await session.commitTransaction().catch(error => {
            console.log(error);
        });
        session.endSession()
    } catch (error) {
        await session.abortTransaction().catch(error => {
            console.log(error);
        });
        session.endSession();
        throw error;
    }
}

Above code completely work on local system. but erro occure on cloud server (Digital ocean) Please let me know if another information needed.

like image 559
Lalit Patil Avatar asked Oct 17 '22 09:10

Lalit Patil


1 Answers

It seems you haven't installed MongoDB 4.0 on your cloud server which supports transactions.

Transaction works only with >= MongoDB v4.0

like image 122
Shivam Pandey Avatar answered Oct 30 '22 14:10

Shivam Pandey