Unable to query Mongo queries after updating project to "forest-express-mongoose": "^7.7.1"

Hey guys. I started forest admin project a couple of months ago, when I was using “forest-express-mongoose”: “6.0.0” and at the time, we exported models as Model Type which made it easier to write queries directly through mongoose models.

However, after upgrading forest-express-mongoose to 7.7.1, I am unable to write queries because the models are now returned from a function. I tried the code below but the result doesnt return anything.

const transactionModel = require(’…/models/transactions’);
const mongoose = require(‘mongoose’);

let model = transactionModel(mongoose, mongoose)
let result = await model.findOne({})

Can someone help me on how to query models when it is returned as a function???

Regards,
Tanish P

Hey @tanishp, and welcome to our community :wave:

As stated in the documentation, all your models should be exported by the models/index.js.

Using

const { transactions } = require('../models');

instead of const transactionModel = require(’…/models/transactions’);
should allow you to get the instanciated model instead of the function.

Let me know if that helps :raised_hands:

1 Like

It worked, thank you so much for the fast reply. Great stuff.

1 Like