https://github.com/holyshared/mongoose_example
https://github.com/holyshared/mongoose_example
Last synced: 10 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/holyshared/mongoose_example
- Owner: holyshared
- License: mit
- Created: 2019-07-06T07:52:32.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2021-05-09T23:43:06.000Z (about 5 years ago)
- Last Synced: 2025-07-20T01:30:21.987Z (11 months ago)
- Language: JavaScript
- Size: 16.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Mongoose example
## 環境構築
docker-composeをインストールして、コンテナを起動する。
```
docker-compose up -d
```
## 実験
### 実験-1
~~ネストしたIDにObjectIdでの参照がある場合は、**populate**した時にドキュメントの構造が期待した状態にならない。~~
~~**mapReduce**で集計した結果をフェッチする場合は、気を付ける必要がある。~~
**populate**の**path**が間違っていると、ドキュメントの構造が期待した状態にならない。
```js
const query = { category: cat._id, year: 2019, month: 1 };
// .でパスを表現しないとダメな模様
// const options = { populate: { path: '_id', populate: { path: 'category' } } };
const options = { populate: { path: '_id.category' } };
const report = await ReportStats.findById(query, null, options);
```
#### 期待する結果
```js
{
_id: {
category: { ... },
year: 2019,
month: 2019,
}
}
```
#### 結果
```js
{ _id: [], value: 1 } // _idが配列になってしまう
```