Questions tagged [typegoose]
Typegoose is a wrapper for Mongoose schema & models to better work in TypeScript.
137
questions
0
votes
2
answers
49
views
Typegoose + mongoose: how to push tuple to array?
I'm working on the following code:
import { prop, modelOptions, DocumentType, getModelForClass } from "@typegoose/typegoose";
import dbConnect from "src/lib/dbConnect";
import ...
0
votes
0
answers
38
views
Typegoose and TypeGraphQL - @FieldResolver not working
I have try to get the user by the userid which stored in the notice, but I get undefined in the FieldResolver.
Notice Schema
@ObjectType({description: "Notice Schema"})
export class Notice ...
0
votes
0
answers
44
views
Typegoose generic manager error with compiler
I'm having some issues with the creation of a generic manager with typegoose and mongoose
export class Manager<T extends types.AnyParamConstructor<any>> {
model: ReturnModelType<T>;...
1
vote
2
answers
147
views
Typegoose/ Mongoose nested discriminator is not accepting array
I am building a Node application using TypeScript and MongoDB as my application's database. I am using Typegoose to interact with MongoDB from Node JS application. Now, I am having a problem with ...
1
vote
1
answer
171
views
How to query recursive MongoDB Document [File System of files and folders]
I am developing an application that uses MongoDB (typegoose) to store file system-like (recursive) documents composed of files and folders. However, I do not know how to query such a schema. For ...
0
votes
0
answers
28
views
Unexpected format when using fieldresolver from type-graphql with typegoose
The structure of my user object returned from typegoose is unexpected.
@Resolver((of) => User)
export class UserResolver {
@FieldResolver(() => String, { nullable: true })
email(@Root() user:...
0
votes
1
answer
94
views
How can I populate nested documents in Typegoose?
Let's say I have 3 schemas.
class User {
@Prop()
name: string
}
class Exam {
@Prop()
name: string
@Prop({ ref: () => Exam }, PropType.ARRAY)
examReq?: Ref<Exam>[]
}
...
0
votes
0
answers
46
views
Jest timeout when I try to save mongoose document
Stack : Typescript, Typegoose, Jest, Mongo Memory Server
I'm trying to save a doc during a test but as soon as I'm trying to await the save, the test timeout.
I've setup the connection to the db ...
1
vote
0
answers
47
views
Update mongoose connection credentials when secrets are rotated
I have a Node.js / Nest.js web service, connected to a MongoDB using typegoose / mongoose. The app runs in a K8s container alongside a Vault service that periodically rotates the mongoDB client's ...
0
votes
0
answers
236
views
"Cannot read properties of undefined reading router" Error message using TSYRINGE
I'm building a class-based restFul API using TypeScript and expressJS with clean architecture, I'm practicing with Typegoose and Tsyringe just to learn how to make dependency injection in this ...
0
votes
0
answers
78
views
Mongoose, update values in array of objects for specific filter condition
I'am having issues updating a document with an array of objects, I'm using typegoose to define schemas and models and I only want to update a specific value from the array of objetcs. Here is the code....
1
vote
2
answers
26
views
mongoose-unique-validator not working with typegoose nested object
I'm using typegoose nested classes with mongoose-unique-validator as follows
import {
prop,
plugin,
post,
index,
getModelForClass,
} from "@typegoose/typegoose";
const ...
0
votes
1
answer
106
views
Typegoose Mongoose Enum error - Array of strings
I have an enum:
export enum Careers {
WEB_DEVELOPMENT = 'Web Development',
MOBILE_DEVELOPMENT = 'Mobile Development',
UI_UX = 'UI/UX'
}
This is the mongoose property
@Prop({ type: [String], ...
0
votes
1
answer
295
views
Error: "User.email"'s Type is invalid! Type is: "undefined" [E009]
I get this error after i transpiled my typescript to javascript and using typegoose for my model, dont know the fix, anybody here?
at getModelForClass (/Users/user/Documents//node_modules/@typegoose/...
0
votes
1
answer
61
views
Make a user object property resolved inside @FieldResolver (posts)
I am creating a reddit clone, using a type-graphql, express-graphql and typegoose,
first i run a query for posts and i get the user info (_id, username) :
query posts {
posts {
_id
title
...
0
votes
1
answer
41
views
Typegoose - pass arbitrary JSON objects to array
I have a Typegoose model (simplified)
export class SurveyClass extends BaseClass {
@prop({ required: true, default: '' })
public description!: string;
@prop({ required: true, default: [] })
...
0
votes
1
answer
471
views
How Do solve the following Node Typescript Error
/Users/oforduhh/Documents/EXPRESS JS/ts_api_auth/node_modules/ts-node/dist/index.js:851
return old(m, filename);
^
Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/...
0
votes
0
answers
60
views
How to use Typegoose getDiscriminatorModelForClass with an Array
Is there a way to use this getDiscriminatorModelForClass function with an Array of objects?
This is an Example on the website, but basically i want to abb more than one event to one ClickEvent class. ...
0
votes
1
answer
155
views
Typegoose Ref returns null on parent object despite assigning a parent in child
I' trying to set up a simple example from typegoose documentation with TypeGraphQl
Here are my types for child:
export enum Behavior {
A = "good kitten",
B = "very good kitten",...
0
votes
1
answer
243
views
Typegoose return PopulatedType from ref
I have a problem using Typegoose, I have defined a Ref on my schema like this:
export class LocationEntity {
@prop({ type: () => [String] })
public state: string[];
@prop({ type: () =&...
0
votes
1
answer
25
views
Adding parent field value in subdocuments while concating
I want to add parent field value inside its subDocs
I want task name inside all of its subdocuments. Example document:
{
_id: 1,
tasks: [
{
_id: 1,
assigned: [
...
0
votes
1
answer
211
views
Mongoose populate one field from another id field
I am currently having 2 fields as follows in typegoose (provides better typings for mongoose)
class User {
@prop()
public car: Car; // This is a single Reference
@prop()
public carId: Ref<...
0
votes
1
answer
146
views
TypeScript Generics Multiple Return Types With TypeSafety
I am working on a multitenant app and in that, I use mongoose & typegoose in combination to switch the DB for specific tenants.
Below is a minimal reproducible code that can be seen by installing ...
2
votes
0
answers
252
views
Cannot return null for non-nullable field Apollo GraphQL
This is my model:
export class Task extends BaseModel {
@Field()
@prop({ required: true })
title!: string
@Field()
@prop({ required: true })
index!: number
@Field(() =>...
1
vote
1
answer
407
views
Merge nested array data in single array and get them into root of document
I am struggling with retrieving nested document in root.
below i have a schema inside it there is a array of tasks in which objects are present,
in those objects there is again an array of assigned ...
1
vote
1
answer
144
views
Multitanancy using typegoose , nestjs framework
I am trying to build multitenancy functionality, each tenant will have its own database.
Is this possible to create dynamically the connections using typegoose?
0
votes
0
answers
74
views
Test Type-Graphql with mongoose
I am pretty new in unit testing, I want to test my application that is written in node, the technologies I use are express.js, type-graphql, and type-goose, I searched a lot on the web to find some ...
0
votes
1
answer
120
views
Why Typegoose references can always be undefined even when they are required?
I'm using Typegoose. Here is my Invoice class.
export class Invoice extends StatusHistory {
@prop({ required: true })
name!: string;
}
Here is my Contract class.
export class Contract extends ...
0
votes
1
answer
243
views
Add a new field to the Typegoose subdocument
How do I include an extra field in the User class subdocument?
class Car {
@prop()
public model?: string;
}
class User {
@prop()
public name?: string;
@prop({ required: true })
public ...
0
votes
0
answers
154
views
Elasticsearch routing pass at runtime using Typegoose with Mongoosastic
I am trying to create a Typegoose model with Mongoosastic as a plugin to it.
My current code is as below where I have passed routing as 'some_key' as hard-coded string, but I need to pass it runtime ...
1
vote
1
answer
136
views
Protect fields from GraphQL querying
I have this User model in TypeGraphQL with TypeGoose:
@index({ email: 1 })
@queryMethod(findByEmail)
@ObjectType()
export class User {
@Field(() => String)
_id: string;
@Field(() => ...
0
votes
0
answers
54
views
Updating objects containing arrays in mongoose
I have an object coming in from the frontend, structure of which is as follows:
{
name: 'John Doe',
gender: 'male',
age: 28,
preferredTags: ["JavaScipt", "Rails", &...
0
votes
0
answers
41
views
Setting user interface type doesn't work while finding user
setting type is not working. It shows
Type '(Document<string, BeAnObject, any> & UserSchema &
IObjectWithTypegooseFunction & { _id: string; })[]' is missing the
following properties ...
1
vote
1
answer
553
views
Cannot return null for non-nullable field - Typegoose and TypeGraphQL
I have this Album model set up using Typegoose and TypeGraphQL, which contains multiple songs from the Song model using the AlbumSong ObjectType:
import {
prop as Property,
getModelForClass,
...
1
vote
1
answer
70
views
How to add index weight on two id fields on MongoDB?
I have a question regarding Mongo indexes for a $or request on two ObjectID fields.
How can I make sure a search will first look at the first argument of the $or expression and only then if no match ...
1
vote
3
answers
244
views
Mongodb Populate is not populating document in Node.js
I am using typegoose and my Query and QueryRule models are as below.
export class Query {
@prop()
queryRule: Ref<QueryRule>;
}
export class QueryRule {
@prop()
condition: Condition;
@...
1
vote
0
answers
125
views
Typegoose not working with vuetify in electron
Im trying to build a very simple model with typegoose inside Vue + electron.
This is my simplified code:
import { getModelForClass, prop, modelOptions } from '@typegoose/typegoose';
@modelOptions(...
1
vote
0
answers
273
views
Need to set correct type for mongoose document
I have an abstract class that takes a mongoose model and does some manipulation.
export default class ItemManager {
private _req: Request;
private _res: Response;
private _dbModel: mongoose....
1
vote
0
answers
201
views
Typegoose, graphql, how to update fields with object types
I have a user schema:
@ObjectType()
export class User {
@Field(() => String)
_id: string;
@Field(() => String)
@prop({ required: true })
userName: string;
@Field(() => UserType)
...
1
vote
1
answer
458
views
Reference Mongodb schema from other microservices
I currently have a microservice architecture powered by Apollo Federation, where a service has its own database. Consider this example, the user's service has its own database, the posts service has ...
0
votes
1
answer
243
views
Sort the data by the populated field by typegoose in mongodb
I have the three collections as following:
export class TopClass implements Base {
@prop()
name: string;
@prop({ ref: () => SecondClass})
second: SecondClass;
}
export class SecondClass ...
0
votes
1
answer
71
views
GrahpQL Mutation not returning value of FieldResolver
I'm using TypeGraphQL and Typegoose to have and API for category trees stored by a reference to the parent. One FieldResolver of it is returning an array of ancestors (using graphLookup).
@...
0
votes
1
answer
265
views
Inconsistent id refs in mongo/typegoose project
When debugging my mongodb/typegoose backed I found out that I have a very inconsistent way of referring to related fields.
tags: [
ObjectId("61e73da868987d7565732dce"),
ObjectId("...
0
votes
1
answer
216
views
How to reference an another class with non _id field in typegoose?
I'm using Typegoose v9.3.1
I need to create a reference for another collection with non _id field using Typegoose.
For example i'm having the following models.
Class collection
export class Class {
@...
1
vote
1
answer
449
views
type GraphQl typegoose backend error while linking models error : Error: Prop-Option "ref"'s value is "null" or "undefined" for "User.projects" [E005]
user schema
projects schema
I've been able to fix it as shown here
however this doesn't seem like the right approach as Its throwing some warnings, also feels very make shift and like Its going to ...
1
vote
1
answer
569
views
Typegoose is not saving array subdocuments properly in Nest.js app
I'm attempting to save an array of TaskOutcome subdocuments in my Task model, following the typegoose documentation:
import { prop } from '@typegoose/typegoose';
class TaskOutcome {
@prop({ ...
2
votes
0
answers
84
views
Typegoose Mongoose Error - Schema hasn't been registered for model
I am facing issue with model registration and I have explained the code over here.
https://github.com/typegoose/typegoose/issues/633
Can anybody please check and share the thoughts.
0
votes
0
answers
397
views
TypeGraphQL Field Resolver returns undefined
I have built my back-end with Typegoose+TypeGraphQL. I have an ObjectType that looks like this:
I want workoutAmount to pretty much just return the length of workouts array. The array always exists, ...
2
votes
0
answers
52
views
How to index only verified values in mongoDB
I am going to write a Cards model for payments. However, I am going to index and make unique only verified cards. Cards model has attribute:status. It can be verified or unverified. First, I wrote ...
-1
votes
1
answer
628
views
typegoose/mongoose What is correct way to get new document from model class
I upgrade mongoose version to 6 and i found...
import {
getModelForClass,
} from "@typegoose/typegoose";
export const ProductModel = getModelForClass(Product); // this give me mongoose ...