How to define ObjectID type column (other than _id)
See original GitHub issueIssue type:
[x] question [ ] bug report [ ] feature request [ ] documentation issue
Database system/driver:
[ ] cordova
[x] mongodb
[ ] mssql
[ ] mysql
/ mariadb
[ ] oracle
[ ] postgres
[ ] sqlite
[ ] sqljs
[ ] react-native
TypeORM version:
[x] latest
[ ] @next
[ ] 0.x.x
(or put your version here)
Steps to reproduce or a small repository showing the problem:
I have an entity :
@Entity()
export class RolePermission implements IRolePermission {
@ObjectIdColumn() id?: ObjectID;
@Column()
@IsNotEmpty()
roleId: ObjectID;
@Column()
@IsNotEmpty()
permissionId: ObjectID;
}
The code compiles. But when I start my server, this error throws :
> node ./dist/server.js
error: ColumnTypeUndefinedError: Column type for RolePermission#roleId is not defined and cannot be guessed. Make sure you have turned on an "emitDecoratorMetadata": true option in tsconfig.json. Also make sure you have imported "reflect-metadata" on top of the main entry file in your application (before any entity imported).If you are using JavaScript instead of TypeScript you must explicitly provide a column type.
I have turned on the option in my tsconfig.json and I import reflect-metadata at the top of my file server.ts.
I read the code about the decorator ObjectIdColumn and if I think it used only for primary use case, so it’s not applicable for my need.
Thanks a lot for your help
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:7 (4 by maintainers)
Top Results From Across the Web
How to set ObjectId as a data type in mongoose - Stack Overflow
After setting a virtual property, I tried: db.cats.find({categoryId: ObjectId("the id")}) but got null results. when I use db.cats.find({_id ...
Read more >Fundamentals of ObjectID fields—Help | ArcGIS Desktop
In ArcMap or ArcCatalog, you can open the table's Properties dialog box and click the Fields tab. If there is no field listed...
Read more >ObjectId — MongoDB Manual
Generate a New ObjectId. To generate a new ObjectId, use ObjectId() with no argument: x = ObjectId() ; Specify a Hexadecimal String. To...
Read more >What Is MongoDB's _id Field and How to Use It - Orange Matter
As MongoDB documentation explains, "ObjectIds are small, likely unique, fast to generate, and ordered." The _id field is a 12-byte Field of BSON ......
Read more >Fields - ODMantic
The ObjectId data type is the default primary key type used by MongoDB. An ObjectId comes with many information embedded into it (timestamp,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
you need to install mognodb typings and import ObjectID from mongodb, like this:
I know this is confusing, and its something we have to resolve.
Having two ObjectID from various places is pain