Questions tagged [nestjs-mongoose]
46 questions
0
votes
2 answers
NestJs for lambda with mongodb creating too many connections
We are using nestjs for lambda which connects with mongodb for data. We are using nestjs mongoose module. However on deployment for each invocation a new set of connection are made and the previous ones are not released.
We are using…

Hamza Afridi
- 141
- 5
0
votes
0 answers
@nestjs/mongoose, virtual populate with 2 databases
I'm trying to populate userId field which exists in database 1 from user document which exists in database 2.
I've already defined connectionName parameter in MongooseModule.ForRootAsync() I can't find out where the problem is. Also it works if I…

Agent Smith
- 13
- 2
0
votes
2 answers
mongoose only saving _id and __v
I am making an API using nestjs and mongoose. However, I am stuck on a bug. I have asked other people for help, and have tried googe with no luck. In short, my issue is that when making a POST request to the API endpoint, it only saves teh _id and…

codepip55
- 43
- 7
0
votes
0 answers
How to make 2 fields as unique index together in Nestjs
this is my schema
export type OnSaleListDocument = OnSaleList & Document;
@Schema({ autoIndex: true })
export class OnSaleList {
@Prop()
id: number;
@Prop()
address: string;
@Prop()
quantity: number;
@Prop()
price: number;
}
const…
0
votes
1 answer
NestJs fail inserting data into mongoDb
In my application i have a simple method as register and into that i want to insert a simple data into mongo-db and retrieve all saved documents after that, but i get empty always and i can't resolve this issue:
problem is this: i can store data…

DolDurma
- 15,753
- 51
- 198
- 377
0
votes
1 answer
NestJS Mongoose schema definition
I have class, with nested object where I need only one field required and then all other keys are undefined and unlimited with string type, how could I write it in TypeScript?
I have tried this logic:
@Schema({ _id: false })
class Translations…

Dima Binskyi
- 5
- 2
0
votes
1 answer
How to define dynamic key in object in array of objects with @Prop() decorator in schema? Mongoose, NestJS
I have array of object like this
const array = [
{key1: value1},
{key2: value2},
...
]
How to define it correctly in schema with @Prop decorator?
@Schema()
export class Entity{
@Prop() // Here
body: ; // and here
}

Igor
- 3
- 4
0
votes
1 answer
What is the difference between Type[] and [Type] while defining mongoose entity Prop in nestjs
I am using following code to define a mongodb entity.
@Schema({})
export class User extends BaseModel {
@Prop({ type: [String], required: true })
subjects: string[]; // line 1
// subjects: [string]; // line 2
}
What is the difference…
0
votes
0 answers
timestamps not working in a deep array of subdocument
So, im using nestjs to create a rest api and here is my schema
user.schema
repository.schema
commit.schema
as you can see i also set timestamps: true in repository.schema it work but when i set it on commit.schema the timestamps not generating the…

Axselll
- 1
- 1
0
votes
1 answer
how to create nested schema in nestjs use mongodb
email
password
role
confirmed
id
address
city
street
My user schema should be like this. I want it to appear as a nested schema. separate the address space.
export const UserSchema = new mongoose.Schema({
email: { type: String, unique: true,…

oykn
- 190
- 1
- 12
0
votes
1 answer
Why I can't reference by class name related entities in the same module?
My application is built with NestJS and Mongoose and I now need to specify relations between entities that are placed in the same module (User and Profile).
The official documentation shows this:
The User entity file sits in the users directory.…

Ruben
- 21
- 3
0
votes
1 answer
Nestjs Mongoose prop alias always returns undefined
@nestjs/mongoose module.
Mongo collection has different properties than Mongoose model. I use aliases, but they return undefined results.
Mongo document
{
"_id" : ObjectId("5bd6ff5ea392f7302f26c906"),
"limit" : 3,
"filter" : {
…

hdoitc
- 386
- 1
- 10
- 21
0
votes
1 answer
NestJs - How to use the same schema & collection for different connections?
I need to establish two different connections to the same mongodb, but with different connection options (poolSize, readPreference, etc.) of course with different connectionName. The MongooseModules are imported in the AppModule
@Module({
imports:…

Michał Skorzec
- 61
- 7
0
votes
1 answer
How to load embedded reference schema in nestjs mongodb?
Currently I am working on API using nestjs. It has the code like below.
@ObjectType()
@Schema()
@InputType('BuyInput', { isAbstract: true })
export class Buy extends CoreEntity {
@Prop(raw([BuyItemType]))
@Field(() => [BuyItemType])
items:…

Shreejan Acharya
- 329
- 2
- 8
0
votes
0 answers
Nest js mongoose inject connection inside global interceptor
I'm having some trouble injecting the mongoose Connection object inside a global interceptor in nest js. Here is my main module
imports: [
ConfigModule.forRoot({
isGlobal: true,
load: [getConfiguration]
}),
…

Marco Raffaello
- 11
- 2