Skip to content

Commit e67c771

Browse files
Merge branch '4.x' into patch-11
2 parents ca1658a + 7b11d70 commit e67c771

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+3275
-1670
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,7 @@ tools/31*
3434
*.key
3535

3636
docs/*.html
37+
38+
test/files/main.js
39+
40+
.config.js

.npmignore

+4
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@ format_deps.js
1717
tools/31*
1818
*.key
1919
data/
20+
21+
test/files
22+
23+
.config.js

.travis.yml

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
language: node_js
22
sudo: false
33
node_js:
4+
- "9"
5+
- "8"
46
- "7"
57
- "6"
68
- "5"
@@ -9,14 +11,16 @@ node_js:
911
- "0.10"
1012
- "iojs"
1113
before_script:
12-
- wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.6.11.tgz
13-
- tar -zxvf mongodb-linux-x86_64-2.6.11.tgz
14+
- wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.4.23.tgz
15+
- tar -zxvf mongodb-linux-x86_64-3.4.23.tgz
1416
- mkdir -p ./data/db/27017
1517
- mkdir -p ./data/db/27000
16-
- ./mongodb-linux-x86_64-2.6.11/bin/mongod --fork --nopreallocj --dbpath ./data/db/27017 --syslog --port 27017
18+
- printf "\n--timeout 8000" >> ./test/mocha.opts
19+
- ./mongodb-linux-x86_64-3.4.23/bin/mongod --fork --dbpath ./data/db/27017 --syslog --port 27017
20+
- export PATH=`pwd`/mongodb-linux-x86_64-3.4.23/bin/:$PATH
21+
- sleep 3
1722
script:
1823
- npm test
1924
- npm run lint
20-
- npm run nsp
2125
notifications:
2226
email: false

History.md

+147
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,150 @@
1+
4.13.21 / 2020-07-12
2+
====================
3+
* fix(query): delete top-level `_bsontype` property in queries to prevent silent empty queries #8222
4+
5+
4.13.20 / 2020-01-07
6+
====================
7+
* fix(schema): make aliases handle mongoose-lean-virtuals #6069
8+
9+
4.13.19 / 2019-07-02
10+
====================
11+
* fix(aggregate): make `setOptions()` work as advertised #7950 #6011 [cdimitroulas](https://github.com/cdimitroulas)
12+
13+
4.13.18 / 2019-01-21
14+
====================
15+
* fix(model): handle setting populated path set via `Document#populate()` #7302
16+
* fix(cast): backport fix from #7290 to 4.x
17+
18+
4.13.17 / 2018-08-30
19+
====================
20+
* fix(document): disallow setting `constructor` and `prototype` if strict mode false
21+
22+
4.13.16 / 2018-08-30
23+
====================
24+
* fix(document): disallow setting __proto__ if strict mode false
25+
* feat(error): backport adding modified paths to VersionError #6928 [freewil](https://github.com/freewil)
26+
27+
4.13.15 / 2018-08-14
28+
====================
29+
* fix(mongoose): add global `usePushEach` option for easier Mongoose 4.x + MongoDB 3.6 #6858
30+
* chore: fix flakey tests for 4.x #6853 [Fonger](https://github.com/Fonger)
31+
* feat(error): add version number to VersionError #6852 [freewil](https://github.com/freewil)
32+
33+
4.13.14 / 2018-05-25
34+
====================
35+
* fix(model): handle retainKeyOrder option in findOneAndUpdate() #6484
36+
37+
4.13.13 / 2018-05-17
38+
====================
39+
* fix(update): stop clobbering $in when casting update #6441 #6339
40+
* fix: upgrade async -> 2.6.0 re: security warning
41+
42+
4.13.12 / 2018-03-13
43+
====================
44+
* fix(document): make virtual get() return undefined instead of null if no getters #6223
45+
* docs: fix url in useMongoClient error message #6219 #6217 [lineus](https://github.com/lineus)
46+
* fix(discriminator): don't copy `discriminators` property from base schema #6122 #6064
47+
48+
4.13.11 / 2018-02-07
49+
====================
50+
* docs: fix links in 4.x docs #6081
51+
* chore: add release script that uses --tag for npm publish for 4.x releases #6063
52+
53+
4.13.10 / 2018-01-28
54+
====================
55+
* docs(model+query): add lean() option to Model helpers #5996 [aguyinmontreal](https://github.com/aguyinmontreal)
56+
* fix: use lazy loading so we can build mongoose with webpack #5993 #5842
57+
* docs(connections): clarify multi-mongos with useMongoClient for 4.x docs #5984
58+
* fix(populate): handle populating embedded discriminator paths #5970
59+
* docs(query+aggregate): add more detail re: maxTimeMS #4066
60+
61+
4.13.9 / 2018-01-07
62+
===================
63+
* chore: update marked (dev dependency) re: security vulnerability #5951 [ChristianMurphy](https://github.com/ChristianMurphy)
64+
* fix: upgrade mongodb -> 2.2.34 for ipv6 and autoReconnect fixes #5794 #5760
65+
* docs: use useMongooseAggCursor for aggregate docs #2955
66+
67+
4.13.8 / 2017-12-27
68+
===================
69+
* docs(guide): use more up-to-date syntax for autoIndex example #5933
70+
* docs: fix grammar #5927 [abagh0703](https://github.com/abagh0703)
71+
* fix: propagate lean options to child schemas #5914
72+
* fix(populate): use correct model with discriminators + nested populate #5858
73+
74+
4.13.7 / 2017-12-11
75+
===================
76+
* docs(schematypes): fix typo #5889 [gokaygurcan](https://github.com/gokaygurcan)
77+
* fix(cursor): handle `reject(null)` with eachAsync callback #5875 #5874 [ZacharyRSmith](https://github.com/ZacharyRSmith)
78+
* fix: disallow setting `mongoose.connection` to invalid values #5871 [jinasonlin](https://github.com/jinasonlin)
79+
* docs(middleware): suggest using `return next()` to stop middleware execution #5866
80+
* docs(connection): improve connection string query param docs #5864
81+
* fix(document): run validate hooks on array subdocs even if not directly modified #5861
82+
* fix(discriminator): don't treat $meta as defining projection when querying #5859
83+
* fix(types): handle Decimal128 when using bson-ext on server side #5850
84+
* fix(document): ensure projection with only $slice isn't treated as inclusive for discriminators #4991
85+
* fix(model): throw error when passing non-object to create() #2037
86+
87+
4.13.6 / 2017-12-02
88+
===================
89+
* fix(schema): support strictBool option in schema #5856 [ekulabuhov](https://github.com/ekulabuhov)
90+
* fix(update): make upsert option consistently handle truthy values, not just booleans, for updateOne() #5839
91+
* refactor: remove unnecessary constructor check #2057
92+
* docs(query): correct function signature for .mod() helper #1806
93+
* fix(query): report ObjectParameterError when passing non-object as filter to find() and findOne() #1698
94+
95+
4.13.5 / 2017-11-24
96+
===================
97+
* fix(model): handle update cast errors correctly with bulkWrite #5845 [Michael77](https://github.com/Michael77)
98+
* docs: add link to bufferCommands option #5844 [ralphite](https://github.com/ralphite)
99+
* fix(model): allow virtual ref function to return arrays #5834 [brunohcastro](https://github.com/brunohcastro)
100+
* fix(query): don't throw uncaught error if query filter too big #5812
101+
* fix(document): if setting unselected nested path, don't overwrite nested path #5800
102+
* fix(document): support calling `populate()` on nested document props #5703
103+
* fix: add `strictBool` option for schema type boolean #5344 #5211 #4245
104+
* docs(faq): add faq re: typeKey #1886
105+
* docs(query): add more detailed docs re: options #1702
106+
107+
4.13.4 / 2017-11-17
108+
===================
109+
* fix(aggregate): add chainable .option() helper for setting arbitrary options #5829
110+
* fix(aggregate): add `.pipeline()` helper to get the current pipeline #5825
111+
* docs: grammar fixes for `unique` FAQ #5823 [mfluehr](https://github.com/mfluehr)
112+
* chore: add node 9 to travis #5822 [superheri](https://github.com/superheri)
113+
* fix(model): fix infinite recursion with recursive embedded discriminators #5821 [Faibk](https://github.com/Faibk)
114+
115+
4.13.3 / 2017-11-15
116+
===================
117+
* chore: add node 8 to travis #5818 [superheri](https://github.com/superheri)
118+
* fix(document): don't apply transforms to nested docs when updating already saved doc #5807
119+
120+
4.13.2 / 2017-11-11
121+
===================
122+
* feat(buffer): add support for subtype prop #5530
123+
124+
4.13.1 / 2017-11-08
125+
===================
126+
* fix: accept multiple paths or array of paths to depopulate #5798 #5797 [adamreisnz](https://github.com/adamreisnz)
127+
* fix(document): pass default array as actual array rather than taking first element #5780
128+
* fix(model): increment version when $set-ing it in a save() that requires a version bump #5779
129+
* fix(query): don't explicitly project in discriminator key if user projected in parent path #5775 #5754
130+
* fix(model): cast query option to geoNear() #5765
131+
* fix(query): don't treat projection with just $slice as inclusive #5737
132+
* fix(discriminator): defer applying embedded discriminator hooks until top-level model is compiled #5706
133+
* docs(discriminator): add warning to always attach hooks before calling discriminator() #5706
134+
135+
4.13.0 / 2017-11-02
136+
===================
137+
* feat(aggregate): add $addFields helper #5740 [AyushG3112](https://github.com/AyushG3112)
138+
* feat(connection): add connection-level bufferCommands #5720
139+
* feat(connection): add createCollection() helper #5712
140+
* feat(populate): support setting localField and foreignField to functions #5704 #5602
141+
* feat(query): add multipleCastError option for aggregating cast errors when casting update #5609
142+
* feat(populate): allow passing a function to virtual ref #5602
143+
* feat(schema): add excludeIndexes option to optionally prevent collecting indexes from nested schemas #5575
144+
* feat(model): report validation errors from `insertMany()` if using `ordered: false` and `rawResult: true` #5337
145+
* feat(aggregate): add pre/post aggregate middleware #5251
146+
* feat(schema): allow using `set` as a schema path #1939
147+
1148
4.12.6 / 2017-11-01
2149
===================
3150
* fix(schema): make clone() copy query helpers correctly #5752

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ DOCS_ = $(shell find lib/ -name '*.js')
33
DOCS = $(DOCS_:.js=.json)
44
DOCFILE = docs/source/_docs
55
STABLE_BRANCH = master
6-
LEGACY_BRANCH = 3.8.x
6+
LEGACY_BRANCH = 4.x
77

88
test:
99
@MONGOOSE_DISABLE_STABILITY_WARNING=1 ./node_modules/.bin/mocha $(T) --async-only test/*.test.js

README.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ Mongoose is a [MongoDB](https://www.mongodb.org/) object modeling tool designed
55
[![Slack Status](http://slack.mongoosejs.io/badge.svg)](http://slack.mongoosejs.io)
66
[![Build Status](https://api.travis-ci.org/Automattic/mongoose.svg?branch=master)](https://travis-ci.org/Automattic/mongoose)
77
[![NPM version](https://badge.fury.io/js/mongoose.svg)](http://badge.fury.io/js/mongoose)
8-
[![Dependency Status](https://gemnasium.com/Automattic/mongoose.svg)](https://gemnasium.com/Automattic/mongoose)
9-
[![Get help on Codementor](https://cdn.codementor.io/badges/get_help_github.svg)](https://www.codementor.io/vkarpov?utm_source=github&utm_medium=button&utm_term=vkarpov&utm_campaign=github)
108

119
## Documentation
1210

@@ -20,6 +18,16 @@ Mongoose is a [MongoDB](https://www.mongodb.org/) object modeling tool designed
2018
- [Help Forum](http://groups.google.com/group/mongoose-orm)
2119
- [MongoDB Support](https://docs.mongodb.org/manual/support/)
2220

21+
## Importing
22+
23+
```javascript
24+
// Using Node.js `require()`
25+
const mongoose = require('mongoose');
26+
27+
// Using ES6 imports
28+
import mongoose from 'mongoose';
29+
```
30+
2331
## Plugins
2432

2533
Check out the [plugins search site](http://plugins.mongoosejs.io/) to see hundreds of related modules from the community. Next, learn how to write your own plugin from the [docs](http://mongoosejs.com/docs/plugins.html) or [this blog post](http://thecodebarbarian.com/2015/03/06/guide-to-mongoose-plugins).

docs/2.7.x/docs/populate.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ <h1>Populate - DBRef-like behavior</h1>
230230
var Person = mongoose.model('Person', PersonSchema);
231231
</code></pre>
232232

233-
<p>So far we've created two models. Our <code>Person</code> model has it's <code>stories</code> field set to an array of <code>ObjectId</code>s. The <code>ref</code> option is what tells Mongoose in which model to look, in our case the <code>Story</code> model. All <code>_id</code>s we store here must be document <code>_id</code>s from the <code>Story</code> model. We also added a <code>_creator</code> <code>ObjectId</code> to our <code>Story</code> schema which refers to a single <code>Person</code>.</p>
233+
<p>So far we've created two models. Our <code>Person</code> model has its <code>stories</code> field set to an array of <code>ObjectId</code>s. The <code>ref</code> option is what tells Mongoose in which model to look, in our case the <code>Story</code> model. All <code>_id</code>s we store here must be document <code>_id</code>s from the <code>Story</code> model. We also added a <code>_creator</code> <code>ObjectId</code> to our <code>Story</code> schema which refers to a single <code>Person</code>.</p>
234234

235235
<h2>Saving a ref (to the parent)</h2>
236236

docs/connections.jade

+28-23
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ block content
4949
}, 60000);
5050

5151
:markdown
52-
To disable buffering, turn off the [`bufferCommands` option on your schema](http://mongoosejs.com/docs/guide.html#bufferCommands).
52+
To disable buffering, turn off the [`bufferCommands` option on your schema](./guide.html#bufferCommands).
5353
If you have `bufferCommands` on and your connection is hanging, try turning
5454
`bufferCommands` off to see if you haven't opened a connection properly.
5555

@@ -92,7 +92,7 @@ block content
9292

9393
h3#callback Callback
9494
:markdown
95-
The `connect()` function also accepts a callback parameter and returns a [promise](http://mongoosejs.com/docs/promises.html).
95+
The `connect()` function also accepts a callback parameter and returns a [promise](./promises.html).
9696
:js
9797
mongoose.connect(uri, options, function(error) {
9898
// Check error in initial connection. There is no 2nd param to the callback.
@@ -106,26 +106,24 @@ block content
106106

107107
h4#connection-string-options Connection String Options
108108
:markdown
109-
Mongoose supports the following options in the connection string.
110-
111-
* [ssl](http://mongodb.github.io/node-mongodb-native/2.1/api/Server.html)
112-
* [poolSize](http://mongodb.github.io/node-mongodb-native/2.1/api/Server.html)
113-
* [autoReconnect](http://mongodb.github.io/node-mongodb-native/2.1/api/Server.html)
114-
* [socketTimeoutMS](http://mongodb.github.io/node-mongodb-native/2.1/api/Server.html)
115-
* [connectTimeoutMS](http://mongodb.github.io/node-mongodb-native/2.1/api/Server.html)
116-
* [authSource](http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html)
117-
* [retries](http://mongodb.github.io/node-mongodb-native/2.1/api/Server.html)
118-
* [authMechanism](http://mongodb.github.io/node-mongodb-native/2.2/tutorials/connect/authenticating/)
119-
* [reconnectWait](http://mongodb.github.io/node-mongodb-native/2.1/api/Server.html)
120-
* [rs_name](http://mongodb.github.io/node-mongodb-native/2.1/api/ReplSet.html)
121-
* [replicaSet](http://mongodb.github.io/node-mongodb-native/2.1/api/ReplSet.html)
122-
* [nativeParser](http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html)
123-
* [w](http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html)
124-
* [journal](http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html)
125-
* [wtimeoutMS](http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html)
126-
* [readPreference](http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html)
127-
* [readPreferenceTags](http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html)
128-
* [sslValidate](http://mongodb.github.io/node-mongodb-native/2.1/api/Server.html)
109+
You can also specify options in your connection string as [parameters in the query string](https://en.wikipedia.org/wiki/Query_string) portion of the URI.
110+
:js
111+
mongoose.connect('mongodb://localhost:27017/test?connectTimeoutMS=1000', { useMongoClient: true });
112+
// The above is equivalent to:
113+
mongoose.connect('mongodb://localhost:27017/test', {
114+
useMongoClient: true,
115+
connectTimeoutMS: 1000
116+
});
117+
:markdown
118+
The disadvantage of putting options in the query string is that query
119+
string options are harder to read. The advantage is that you only need a
120+
single configuration option, the URI, rather than separate options for
121+
`socketTimeoutMS`, `connectTimeoutMS`, etc. Best practice is to put options
122+
that likely differ between development and production, like `replicaSet`
123+
or `ssl`, in the connection string, and options that should remain constant,
124+
like `connectTimeoutMS` or `poolSize`, in the options object.
125+
126+
The MongoDB docs have a full list of [supported connection string options](https://docs.mongodb.com/manual/reference/connection-string/)
129127

130128
h4#keepAlive A note about keepAlive
131129
.important
@@ -157,9 +155,16 @@ block content
157155

158156
h3#mongos_connections Multi-mongos support
159157
:markdown
160-
High availability over multiple `mongos` instances is also supported. Pass a connection string for your `mongos` instances and set the `mongos` option to true:
158+
High availability over multiple `mongos` instances is also supported.
159+
Pass a connection string for your `mongos` instances. If you are not using
160+
the `useMongoClient` option, you must also set the `mongos` option:
161161
:js
162162
mongoose.connect('mongodb://mongosA:27501,mongosB:27501', { mongos: true }, cb);
163+
:markdown
164+
With `useMongoClient`, you do not need to set the `mongos` option. You also
165+
do **not** need to use `mongos` or `useMongoClient` in mongoose 5.x.
166+
:js
167+
mongoose.connect('mongodb://mongosA:27501,mongosB:27501', { useMongoClient: true }, cb);
163168

164169
h3#multiple_connections Multiple connections
165170
:markdown

docs/documents.jade

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ block content
2222
});
2323
});
2424
:markdown
25-
You can also use [`.set()`](http://mongoosejs.com/docs/api.html#document_Document-set)
25+
You can also use [`.set()`](./api.html#document_Document-set)
2626
to modify documents. Under the hood, `tank.size = 'large';` becomes `tank.set({ size: 'large' })`.
2727
:js
2828
Tank.findById(id, function (err, tank) {
@@ -51,7 +51,7 @@ block content
5151
});
5252
:markdown
5353
The `findAndUpdate/Remove` static methods all make a change to at most one document, and return it with just one call to the database. There [are](./api.html#model_Model.findByIdAndRemove) [several](./api.html#model_Model.findOneAndUpdate) [variations](./api.html#model_Model.findOneAndRemove) on the [findAndModify](http://www.mongodb.org/display/DOCS/findAndModify+Command) theme. Read the [API](./api.html) docs for more detail.
54-
54+
5555
_Note that `findAndUpdate/Remove` do *not* execute any hooks or validation before making the change in the database. You can use the [`runValidators` option](/docs/validation.html#update-validators) to access a limited subset of document validation. However, if you need hooks and full document validation, first query for the document and then `save()` it._
5656

5757
h3 Validating
@@ -61,7 +61,7 @@ block content
6161
h3 Overwriting
6262
:markdown
6363
You can overwrite an entire document using `.set()`. This is handy if you
64-
want to change what document is being saved in [middleware](http://mongoosejs.com/docs/middleware.html).
64+
want to change what document is being saved in [middleware](./docs/middleware.html).
6565
:js
6666
Tank.findById(id, function (err, tank) {
6767
if (err) return handleError(err);

0 commit comments

Comments
 (0)