Mongo: name in columnOptions is not being passed to find query
See original GitHub issueIssue type:
[x] question [x] bug report [ ] feature request [ ] documentation issue
Database system/driver:
[ ] cordova
[x] mongodb
[ ] mssql
[ ] mysql
/ mariadb
[ ] oracle
[ ] postgres
[ ] sqlite
[ ] sqljs
[ ] websql
TypeORM version:
[ ] latest
[ ] @next
[x] 0.1.20
(or put your version here)
Steps to reproduce or a small repository showing the problem:
I have an entity that has a name db name mapping to property name using ColumnOptions:
@Column({
name: 'node_id',
})
nodeId!: string;
I have a query using a repository for this model
async getPageAssociationsForNodeId(nodeId: string) {
const pageAssociations = await this.pageAssociationRepository.find({
nodeId, //typed to Model so this cant be "node_id"
});
return pageAssociations;
}
When I issue this query, looking at the logs in mongo, nodeId
is being passed in the query, not node_id
(name provided in column options):
{
"op" : "query",
"ns" : "<myDb>.PageAssociation",
"command" : {
"find" : "PageAssociation",
"filter" : {
"nodeId" : "12345"
},
"$db" : "slingshot"
},
nodeId
is not the column name in the collection so no results are being returned.
My questions are:
- am I using find appropriately?
- is it wrong to assume that the ColumnOptions.name will be used instead of the property name of the class
- if the answers to the above are “yes” and “no” respectively, is this a bug?
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
mongodb query result without field name - Stack Overflow
Is there a way to get mongodb query results with only the values and not the field names. My query gives me the...
Read more >TypeORM - Amazing ORM for TypeScript and JavaScript (ES7 ...
The quickest way to get started with TypeORM is to use its CLI commands ... Where name is the name of your project...
Read more >Using SQL Runner to create queries and Explores | Looker
Looker passes your query to your database just as you have written it, so be sure that the syntax of your SQL query...
Read more >M001 Query Syntax - MongoDB Basics
See BSON Types. For example, in the mongo shell I created a document in collection called as persons : db.persons.insertOne( { name ......
Read more >Model Basics | Sequelize
This name does not have to be the same name of the table it represents in the database. Usually, models have singular names...
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
Why don’t make this behaviour configurable ?
The ability to decorrelate the technical database name of an attribute from its object representation in programmation language is a key feature of an ORM. The “don’t use
name
” doesn’t match my conception of a professional ORM.I disagree with the fact that 99% of the query are made over
query
in real app. When you create a CRUD API you need this simplefind
query. Moreover for me it’s more dangerous to apply an unpredictable behaviour for simple things than for complexe things.I’m more confused about not having this feature actually. In our system, I want to move from a homemade ‘orm’ to
typeorm
. But our database fields are all alreadysnake_cased
. While in typescript I’d like all my properties to becamelCased
.I’m confused about why it is ‘confusing’ to have this feature on mongo because on other databases it is supported. I’m failing to see why mongo is different in this regard, or why that is wanted.
Implementing a
NamingStrategyInterface
doesn’t seem to work either, it does work for the table names, and thecolumnName
method in the naming strategy is called, but it’s result are ignored.