Current topology does not support session

Viewed 8627

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.

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

Related