mongoose-autopopulate
Advanced tools
Comparing version 0.9.0 to 0.9.1
@@ -81,2 +81,30 @@ | ||
## It has a couple caveats with projections | ||
By default, Mongoose 5.x automatically projects in populated properties. | ||
That means you need a little extra work to exclude autopopulated fields. | ||
Either explicitly [deselect the path](https://mongoosejs.com/docs/api.html#query_Query-select) | ||
in your projection, or set the [`selectPopulatedPaths` schema option](https://mongoosejs.com/docs/guide.html#selectPopulatedPaths) | ||
to `false`. | ||
```javascript | ||
// Mongoose adds `members: 1` and `lead: 1` to the projection | ||
let band = yield Band.findOne().select({ name: 1 }); | ||
assert.equal(band.members[0].name, 'Axl Rose'); | ||
assert.equal(band.lead.name, 'Axl Rose'); | ||
// You can also tell Mongoose to not project in populated paths by default | ||
// using the `selectPopulatedPaths` schema option. | ||
const newSchema = Band.schema.clone(); | ||
newSchema.options.selectPopulatedPaths = false; | ||
let Band2 = mongoose.model('Band2', newSchema, 'bands'); | ||
band = yield Band2.findOne().select({ name: 1 }); | ||
assert.ok(!band.members); | ||
assert.ok(!band.lead); | ||
``` | ||
## It can specify an options argument | ||
@@ -212,3 +240,3 @@ | ||
## It with `lean()` | ||
## It requires an option to work with lean | ||
@@ -215,0 +243,0 @@ |
@@ -0,1 +1,5 @@ | ||
0.9.1 / 2019-01-02 | ||
================== | ||
* docs: add note about selectPopulatedPaths option #50 | ||
0.9.0 / 2018-11-08 | ||
@@ -2,0 +6,0 @@ ================== |
{ | ||
"name": "mongoose-autopopulate", | ||
"version": "0.9.0", | ||
"version": "0.9.1", | ||
"description": "Always populate() certain fields in your mongoose schemas", | ||
@@ -28,2 +28,3 @@ "main": "index.js", | ||
"co": "4.6.0", | ||
"co-mocha": "1.2.2", | ||
"mocha": "5.1.1", | ||
@@ -30,0 +31,0 @@ "mongoose": "~5.3", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29417
8