Automattic / Automattic/mongoose

Schema.path('path to object') returns undefined

Open
#7,408 1 comment 0 reactions 0 assignees View on GitHub
backwards-breaking enhancement
Dominant language
JavaScript
Stars
27.5k
Forks
4k
Avg merge
2d 7h
Merged PRs (30d)
35

Description

**Do you want to request a *feature* or report a *bug*?**

bug

**What is the current behavior?**

`MySchema.path('path to object')` returns `undefined`.

**If the current behavior is a bug, please provide the steps to reproduce.**

Having:
```ts
const UserSchema = new Schema({
test1: {
a: String
},
test2: {
type: {
a: String
}
},
test3: [{
a: String
}]
});
```
Will make
`MySchema.path('test1')` == `undefined`.

While the other ones work:
`MySchema.path('test2')` != `undefined`.
`MySchema.path('test3')` != `undefined`.

**What is the expected behavior?**

I would expect `test1` to work the same way as `test2`.

**Please mention your node.js, mongoose and MongoDB version.**
Node v11.6.0
Mongoose: 5.4.3
MongoDB: v4.0.4

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the behavior with the supplied UserSchema definition and the three Schema.path() calls, using the reported Node, Mongoose, and MongoDB versions if available. Trace how Schema.path() handles nested objects versus typed objects and arrays; done means test1 resolves consistently with test2 and test3, with coverage for the reported shape.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, mongodb, node.js
Domain
backend, databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.