Questions tagged [nestjs-mongoose]
46 questions
9
votes
2 answers
how to set Enums in @nestjs/mongoose schema
this is my schema and i want to set the role to enum
@Prop({ required: true })
name: string;
@Prop({ required: true })
email: string;
@Prop({ required: true })
password: string;
@Prop()
role: string;
this is how i used to do in mongoose
role: {
…

Muhammad Mustafa
- 121
- 1
- 9
8
votes
7 answers
NestJS/Mongoose: serialization does not exclude properties in plain output
I've started to play with NestJS, migrating from my old express/mongoose project and immediately crashed into a fence, just following MongoDB/serializations chapters from NestJS docs. I've prepared following schema
/////// schema
import { Prop,…

kosmo
- 101
- 2
- 9
4
votes
1 answer
Mongoose, how to enforce LeanDocument type?
In our codebase we've been using T.lean() or T.toObject() and our return types would be LeanDocument. Mongoose 7 no longer exports LeanDocument, and the existing migration guide suggests using the following setup:
// Do this instead, no `extends…

EcksDy
- 1,289
- 9
- 25
3
votes
1 answer
NestJS: Mongoose timestamp properties in generated OpenAPI spec
I'm using @Schema({ timestamps: true }) to add createdAt & updatedAt to my records and returning these with the response. But seems the OpenAPI spec getting generated by the NestJs's Swagger plugin is not adding the createdAt or updatedAt. How can I…

Milindu Sanoj Kumarage
- 2,714
- 2
- 31
- 54
3
votes
1 answer
Querying views with nestJS/mongoose
As the title suggests, I am a little confused about working with pre-aggregated views on collections trough Mongoose. I'am able to create a view via the this.connection.createCollection() method -after injecting the connection option- but how should…

Esteday
- 41
- 3
3
votes
1 answer
Documentation of @nestjs/mongoose
I started learning NestJS, by reading documentation. currently, I'm using the @nestjs/mongoose package for MongoDB. unforunatley I can't find any documentation about this package.
the only docs I found is this…

Andronik Nazaryan
- 101
- 2
- 10
3
votes
1 answer
how to reference nested documents in nestjs mongoose typescript
I'm new with nestjs. I use @nestjs/mongoose and I need to reference several fields in a nested object in my class schema and I don't know how to do it.
The dietDays object must contain a date field and meals object that contain a 2 references to…

soheib
- 90
- 5
3
votes
0 answers
Nestjs dependency injection order when a module depends on a Mongoose model from @nestjs/mongoose, detailed diagram inside
The diagram does a good job at explaining the flow I currently have and why that is failing.
I have logger.module that exports a loger.service that depends on a @nestjs/mongoose LogModel.
I have a db.module that exports session.service and imports…

SebastianG
- 8,563
- 8
- 47
- 111
2
votes
0 answers
How to populate Nestjs mongoose schema records
I want to get then enteries from paris air quality, but the thing is that the mongoose schema is nested and I tried to make multiple schemas separated but I don't know wheter it's correct or not.
This is the schema file…

Oussama Bouchikhi
- 527
- 1
- 7
- 22
2
votes
1 answer
Nestjs - use multiple models in a service
I have a Nestjs and MongoDB application.
auth.module.ts -
@Module({
imports: [
MongooseModule.forFeature([{ name: User.name, schema: UserSchema }]),
],
controllers: [AuthController],
providers: [AuthService],
})
export class AuthModule…

vaibhav deep
- 655
- 1
- 8
- 27
2
votes
0 answers
mongoose -- how to start session for transactions from the connection object? always throwing "no transaction started"
I have a nestjs project using mongoose under the hoood to interact with a mongo db.
The issue I'm having is I can't seem to start a session successfully from the connection object itself. Whenever I try to use the resulting session it will throw…

SebastianG
- 8,563
- 8
- 47
- 111
1
vote
1 answer
Error while saving data in nestjs mongoose
I have a post schema:
@Schema({ timestamps: true })
class PostDocument extends Document {
@Prop()
title: string;
@Prop({ type: MongooseSchema.Types.ObjectId, ref: 'Category' })
categoryName: Category
}
And when I am trying to save…

kittu
- 6,662
- 21
- 91
- 185
1
vote
1 answer
Mongoose sub-documents inside nested object
I have a schema which uses multiple fields as reference to other collections in the database.
Everything seems to work fine except for a sub-document which is present in a nested object.
When I try to add the document as a reference to that…

Unknown User
- 3,598
- 9
- 43
- 81
1
vote
2 answers
NestJS: Unable to connect to MongoDB using MongooseModule.forRootAsync
I am trying to connect to local mongoDB in the AppModule by doing the following but it won't connect:
imports: [
MongooseModule.forRootAsync({
useFactory: async () => {
return {
uri: 'mongodb://localhost:27017/client',
…

jackielpy
- 72
- 1
- 11
1
vote
2 answers
Use other model inside useFactory in Nest.Js
How to use other model inside useFactory ?
I want to query by other model before or after save.
But i don't know how to achieve this in @nestjs/mongoose.
check example code below for reference.
MongooseModule.forFeatureAsync([
{
…

keval
- 85
- 10