doug-martin / nestjs-query

Easy CRUD for GraphQL.
https://doug-martin.github.io/nestjs-query
MIT License
820 stars 142 forks source link

MongoDB is not supported by query-typeorm #469

Closed marian2js closed 3 years ago

marian2js commented 4 years ago

Hi, I love the idea of this package and I'd like to use it on my projects. I use MongoDB, which is supported by typeorm, but since query-typeorm makes use of QueryBuilder and other SQL specific calls, it breaks with mongo.

There are plans to support MongoDB?

I had a quick look inside query-typeorm and I think it'd be easier to create a new package like query-typeorm-mongo. Alternatively, the package could support mongoose, which is also well supported by nestjs.

marian2js commented 4 years ago

I started the work on this, although it's still a work in progress:

https://github.com/doug-martin/nestjs-query/pull/474

danielehrhardt commented 4 years ago

For better Search Results: Query Builder is not supported by MongoDB.

doug-martin commented 3 years ago

Published under v0.21.0

onichandame commented 3 years ago

@doug-martin Sorry to revive the dead thread. I am seeing the error Query Builder is not supported by MongoDB with query-typeorm v0.27.0 . Was there any change after 0.21.0?

callyberz commented 3 years ago

Hi any update on this? Having the same issue here.

smolinari commented 3 years ago

There are plans to support MongoDB?

@hkclki - There are two other packages in NestJS-Query that support MongoDB. Nest's MongoDB module and Typegoose both using Mongoose and more feature rich than using TypeORM.

Scott

callyberz commented 3 years ago

There are plans to support MongoDB?

@hkclki - There are two other packages in NestJS-Query that support MongoDB. Nest's MongoDB module and Typegoose both using Mongoose and more feature rich than using TypeORM.

Scott

I was using nestjs's Mongoose but it is not supporting filter, paging, sorting for relationship fields. Thats why I look into TypeORM which it supports Filtering for ref. Is there a way to implement such functions for populated fields in Mongoose?

smolinari commented 3 years ago

@hkclki - In general, you can't directly filter with MongoDB on refs. And, I can't imagine TypeORM does anything differently or rather can offer the filtering ability with MongoDB as the database, but maybe it does. If it does, I'd like to see it in action.

Mongoose does have a populate/ match feature, However be aware, it doesn't filter the parent collection. For example, if you have a bunch of Owners with refs to Dogs, you can't filter the Owners by saying "give me all owners with brown dogs". It would have to be the other way around. You'd query on the Dogs collection (for the ones that are brown), and those documents (should) have refs to the owners, which you can then populate.

The other possibility is to denormalize the data. If you know the dogs' owners will be selected on the color of their dogs (or any other aspect), you could save that in a subdocument array of Dogs, which has the ref to the Dog main document and the denormalized properties (like color and race). This, however, requires extra code and careful consideration for mutations of the Dog documents and subdocuments, where a change might affect both.

Or, you can build your own custom service and have a getOwnersByFilteredDogs method (or something similar) and do a Mongoose aggregation instead of trying to use the built-in nestjs-query services. They are fairly rudimentary at best and only a starting point to save on some repetitive work for your general crud services.

Scott