Skip to content

Commit

Permalink
Merge branch 'master' into gh-9096
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdelrahmanHafez committed Jun 5, 2020
2 parents 8be78a4 + 2d2e0a8 commit 6bccb96
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 5 deletions.
11 changes: 11 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
5.9.18 / 2020-06-05
===================
* fix: improve atlas error in the event of incorrect password #9095
* docs: add edit link for all docs pages #9058
* fix(document): allow accessing `$locals` when initializing document #9099 #9098 [AbdelrahmanHafez](https://github.com/AbdelrahmanHafez)
* fix(query): make `setDefaultsOnInsert` a mongoose option so it doesn't end up in debug output #9086
* docs(connection+index): add serverSelectionTimeoutMS and heartbeatFrequencyMS to `connect()` and `openUri()` options #9071
* docs(geojson): add notes about geojson 2dsphere indexes #9044
* docs: make active page bold in navbar #9062
* docs: correct a typo in a code snippet #9089 [Elvis-Sarfo](https://github.com/Elvis-Sarfo)

5.9.17 / 2020-06-02
===================
* fix(document): avoid tracking changes like `splice()` on slice()-ed arrays #9011
Expand Down
4 changes: 2 additions & 2 deletions lib/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ function Document(obj, fields, skipId, options) {
this.isNew = 'isNew' in options ? options.isNew : true;
this.errors = undefined;
this.$__.$options = options || {};
this.$locals = {};
this.$op = null;

if (obj != null && typeof obj !== 'object') {
throw new ObjectParameterError(obj, 'obj', 'Document');
Expand Down Expand Up @@ -158,8 +160,6 @@ function Document(obj, fields, skipId, options) {
}

this.$__._id = this._id;
this.$locals = {};
this.$op = null;

if (!this.$__.strictMode && obj) {
const _this = this;
Expand Down
4 changes: 3 additions & 1 deletion lib/error/serverSelection.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ class MongooseServerSelectionError extends MongooseError {
assimilateError(err) {
const reason = err.reason;
// Special message for a case that is likely due to IP whitelisting issues.
const isAtlasWhitelistError = isAtlas(reason) && allServersUnknown(reason);
const isAtlasWhitelistError = isAtlas(reason) &&
allServersUnknown(reason) &&
err.message.indexOf('bad auth') === -1;
this.message = isAtlasWhitelistError ?
atlasMessage :
err.message;
Expand Down
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ Mongoose.prototype.pluralize = function(fn) {
* var mongoose = require('mongoose');
*
* // define an Actor model with this mongoose instance
* const Schema = new Schema({ name: String });
* const schema = new Schema({ name: String });
* mongoose.model('Actor', schema);
*
* // create a new connection
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "mongoose",
"description": "Mongoose MongoDB ODM",
"version": "5.9.17",
"version": "5.9.18",
"author": "Guillermo Rauch <guillermo@learnboost.com>",
"keywords": [
"mongodb",
Expand Down
18 changes: 18 additions & 0 deletions test/document.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9052,6 +9052,24 @@ describe('document', function() {
});
});

it('allows accessing $locals when initializing (gh-9098)', function() {
const personSchema = new mongoose.Schema({
name: {
first: String,
last: String
}
});

personSchema.virtual('fullName').
get(function() { return this.$locals.fullName; }).
set(function(newFullName) { this.$locals.fullName = newFullName; });

const Person = db.model('Person', personSchema);

const axl = new Person({ fullName: 'Axl Rose' });
assert.equal(axl.fullName, 'Axl Rose');
});

describe('Document#getChanges(...) (gh-9096)', function() {
it('returns an empty object when there are no changes', function() {
return co(function*() {
Expand Down

0 comments on commit 6bccb96

Please sign in to comment.