Automattic / Automattic/mongoose

Support array methods on embedded document

Open
#4,003 1 comment 0 reactions 0 assignees View on GitHub
discussion new feature
Dominant language
JavaScript
Stars
27.5k
Forks
4k
Avg merge
2d 7h
Merged PRs (30d)
35

Description

```
var ChildSchema = new Schema({
});

var ParentSchema = new Schema({
children : [ChildSchema]
});
```

Besides of defining methods on each `child` document by `ChildSchema.statics.doSomething` and `ChildSchema.methods.getSomething`, I want to define methods directly in the `parent.children` array, something like:

```
ChildSchema.arrayMethods.mySortFunction = function () { ... };
ChildSchema.arrayMethods.getEldest = function () { ... };
```

It could be a great feature

Contributor guide

Open the contributing guide

Research direction

The issue names ChildSchema.arrayMethods and the parent.children embedded-document array, but no files or tests. Start by reviewing Mongoose's embedded-document array API and existing array-method behavior, then clarify whether methods such as mySortFunction and getEldest should be inherited and how they should behave. Done means the supported API is defined, implemented, and covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, mongodb, nodejs
Domain
backend, database
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.