Mongoose has no `DocumentToObjectOptions` - nestjs-query

I've been following the guide and then the example, but I always get the following error message:

node_modules/@nestjs-query/query-mongoose/dist/src/services/mongoose-query.service.d.ts:2:20 - error TS2305: Module '"mongoose"' has no exported member 'DocumentToObjectOptions'.

A quick search in the mongoose repository shows that DocumentToObjectOptions does indeed not exist and never has. It seems like this is because mongoose 5.11 now uses it's own typings? I have other problems though, when downgrading, so I cannot try this.

Have you read the Contributing Guidelines?

Yes, I have

To Reproduce Steps to reproduce the behavior: 1. Follow the example with mongoose

Expected behavior Successful build.

Desktop (please complete the following information): - Node Version 12.16.0 - Nestjs-query Version 0.21.2

Asked Sep 29 '21 00:09
avatar tillsanders
tillsanders

5 Answer:

@tillsanders I've not tried mongoose 5.11 yet, but looking at the issues in their repo this is pretty common with some people removing the mongoose types and installing @types/mongoose I'll need to try to upgrade to 5.11 in order to see what's going on, as I suspect there is more than just the DocumentToObjectOptions missing or not working.

1
Answered Dec 30 '20 at 23:20
avatar  of doug-martin
doug-martin

FYI and not completely relevant, but Typegoose has frozen their Mongoose version because of the changes in types.

Scott

1
Answered Dec 31 '20 at 05:36
avatar  of smolinari
smolinari

@tillsanders Altough downgrading seems not to be a viable option for you, I just wanted to share the combination of package versions that apparently works for me (tm):

"dependencies": {
   "@nestjs/mongoose": "~7.1.2",
   "mongoose": "5.10.0 - 5.10.18"
},
"devDependencies": {
   "@types/mongoose": "^5.10.2"
}

@doug-martin is there anything we could help with?

1
Answered Jan 12 '21 at 21:35
avatar  of Perni1984
Perni1984

@Perni1984 - 5.10.18 is where Typegoose froze at too. Seems 5.10.19 and higher is where the new types start breaking things.

Scott

1
Answered Jan 13 '21 at 05:06
avatar  of smolinari
smolinari

@tillsanders the latest version includes support for v5.11.x! Let me know if you have any issues.

1
Answered Feb 08 '21 at 04:31
avatar  of doug-martin
doug-martin