schema type auto infer bugs
See original GitHub issuePrerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the bug has not already been reported
Mongoose version
6.4.2
Node.js version
18
MongoDB server version
5.0
Description
I’ve found a few more bugs in auto infer type
- Adding an object directly to the array doesn’t infer type correctly
const userSchema = new Schema({
users: [
{
username: { type: String }
}
]
});
- passing function in default makes the key optional
const userSchema = new Schema({
createdAt: { type: Date, default: Date.now }
});
- Array type becomes
Array
instead ofTypes.DocumentArray
which makes pushing fields difficult
const userSchema = new Schema({
users: [
new Schema({
username: { type: String },
credit: { type: Number, default: 0 }
})
]
});
const userModel = model('user', userSchema);
const data = await userModel.findOne();
data!.users.push({ username: 'parbez' });
// ts warns to add createdAt which can be solved using Types.DocumentArray
- Adding empty object as default doesn’t makes the key required
const userSchema = new Schema({
data: { type: { role: Object }, default: {} }
});
- Assigning an object directly to a key doesn’t infer type correctly
const userSchema = new Schema({
data: {
username: String
}
});
Steps to Reproduce
added code blocks above
Expected Behavior
No response
Issue Analytics
- State:
- Created a year ago
- Comments:13 (9 by maintainers)
Top Results From Across the Web
Open-sourcing Facebook Infer: Identify bugs before you ship
Today, we're open-sourcing Facebook Infer, a static program analyzer that Facebook uses to identify bugs before mobile code is shipped.
Read more >In Loving Memory of Strictly-Typed Schemas | SSENSE-TECH
How does one infer a schema? Do you write an algorithm to make an educated guess based on a subset of homogenous data?...
Read more >Unable to infer schema when loading Parquet file
This error usually occurs when you try to read an empty directory as parquet. Probably your outcome Dataframe is empty.
Read more >Auto Loader FAQ | Databricks on AWS
The schema is inferred when the DataFrame is first defined in your code. During each micro-batch, schema changes are evaluated on the fly; ......
Read more >Databricks Runtime 9.1 LTS - Azure - Microsoft Learn
Array and map types are supported in Override schema inference with schema hints for Auto Loader. Examples of schema hints for arrays ...
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 FreeTop 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
Top GitHub Comments
Waiting for maintainer response.
resulting to a type of
but it should be