Unable to run an update using getMongoRepository
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
[ ] expo
TypeORM version:
[ ] latest
[ ] @next
[x] 0.2.10
(or put your version here)
Steps to reproduce or a small repository showing the problem:
The current model looks like this.
import { Answer } from "./Answer";
@Entity({ database: DATABASE_MONGO_NAME })
export class StudentRecord {
@ObjectIdColumn()
_id: ObjectID;
/* many more columns */
@Column()
answers: Answer[];
}
The Answer
collection model looks like this
@Entity({ database: DATABASE_MONGO_NAME })
export class Answer {
@ObjectIdColumn()
_id: ObjectID;
/* many more columns */
@ObjectIdColumn()
mongo_id_question: ObjectID;
@Column()
selected: string[];
}
So essentially the data stored in a document looks like this
{
"_id": {
"$oid": "5c1e60352f73e9000494e33f"
},
"answers": [
{
"_id": {
"$oid": "5c0e507f0da2560004c9003e"
},
"mongo_id_question": {
"$oid": "5c0e507f0da2560004c9003e"
},
"selected": [
"5c0e507f0da2560004c9003b"
]
}
]
}
The query I am trying to run, sets the updatedAt
column for an object with a given mongo_id_question
in the answers
list based on a given record_id
StudentRecordsRepository.update(
{
_id: new ObjectID(record_id),
"answers.mongo_id_question": new ObjectID("5c0e507f0da2560004c9003e"),
},
{ $set: { "answers.$.updatedAt": new Date() } },
);
I get the following error in typescript
error TS2345: Argument of type '{ _id: ObjectID; "answers.mongo_id_question": ObjectID; }' is not assignable to parameter of type 'string | number | Date | ObjectID | FindConditions<StudentRecord> | string[] | number[] | Date[] | ObjectID[]'.
Object literal may only specify known properties, and '"answers.mongo_id_question"' does not exist in type 'string | number | Date | ObjectID | FindConditions<StudentRecord> | string[] | number[] | Date[] | ObjectID[]'
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
TypeORM MongoDB repository won't save every time
I use save() for updating and inserting. Everything is fine on insertion. Here is my code (TypeORM with NestJS) : ==> Entity @Entity()...
Read more >Update Guide to Version 3 - FoalTS
This guide will take you step by step through the upgrade to version 3. If something is missing or incorrect, feel free to...
Read more >typeorm/typeorm - Gitter
Entities are on different applications so we can't add decortors like @ManyToOne() and when We use migration:generate this drop our existing foreign keys....
Read more >Class MongoRepository<Entity> - typeorm
Repository used to manage mongodb documents of a single entity type. ... Find a document and update it in one atomic operation, requires...
Read more >TypeORM - Quick Guide - Tutorialspoint
TypeORM is an easy-to-use ORM to scaffold new apps that connect to databases. ... Easily insert, update and delete object in the database....
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
Be that as it may, this seems like a question for stack overflow and not the answer to the current issue that is being faced.
IMHO I never got why people need an ORM for mongoDb. It is already object oriented. What advantages bring an ORM ? Using an ORM for mongoDB means that models are stored as relational models and that’s a pity because you loose all the benefits of an object oriented database.
In PHP world, Doctrine try to do it with DoctrineODM but it was a failure and poorly used