You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/documents.jade
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -22,7 +22,7 @@ block content
22
22
});
23
23
});
24
24
: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)
26
26
to modify documents. Under the hood, `tank.size = 'large';` becomes `tank.set({ size: 'large' })`.
27
27
:js
28
28
Tank.findById(id, function (err, tank) {
@@ -51,7 +51,7 @@ block content
51
51
});
52
52
:markdown
53
53
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
+
55
55
_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._
56
56
57
57
h3 Validating
@@ -61,7 +61,7 @@ block content
61
61
h3 Overwriting
62
62
:markdown
63
63
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).
Copy file name to clipboardExpand all lines: docs/faq.jade
+4-4Lines changed: 4 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -95,7 +95,7 @@ block content
95
95
:markdown
96
96
**A**. This is a performance optimization. These empty objects are not saved
97
97
to the database, nor are they in the result `toObject()`, nor do they show
98
-
up in `JSON.stringify()` output unless you turn off the [`minimize` option](http://mongoosejs.com/docs/guide.html#minimize).
98
+
up in `JSON.stringify()` output unless you turn off the [`minimize` option](./guide.html#minimize).
99
99
100
100
The reason for this behavior is that Mongoose's change detection
101
101
and getters/setters are based on [`Object.defineProperty()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty).
@@ -104,11 +104,11 @@ block content
104
104
mongoose defines properties on the `Model` prototype when the model is compiled.
105
105
Because mongoose needs to define getters and setters for `nested.prop`, `nested`
106
106
must always be defined as an object on a mongoose document, even if `nested`
107
-
is undefined on the underlying [POJO](http://mongoosejs.com/docs/guide.html#minimize).
107
+
is undefined on the underlying [POJO](./guide.html#minimize).
108
108
109
109
hr#arrow-functions
110
110
:markdown
111
-
**Q**. I'm using an arrow function for a [virtual](http://mongoosejs.com/docs/guide.html#virtuals), getter/setter, or [method](http://mongoosejs.com/docs/guide.html#methods) and the value of `this` is wrong.
111
+
**Q**. I'm using an arrow function for a [virtual](./guide.html#virtuals), getter/setter, or [method](./guide.html#methods) and the value of `this` is wrong.
112
112
113
113
**A**. Arrow functions [handle the `this` keyword much differently than conventional functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions#No_binding_of_this).
114
114
Mongoose getters/setters depend on `this` to give you access to the document that you're writing to, but this functionality does not work with arrow functions. Do **not** use arrow functions for mongoose getters/setters unless do not intend to access the document in the getter/setter.
@@ -215,7 +215,7 @@ block content
215
215
**Q**. All function calls on my models hang, what am I doing wrong?
216
216
217
217
**A**. By default, mongoose will buffer your function calls until it can
218
-
connect to MongoDB. Read the [buffering section of the connection docs](http://mongoosejs.com/docs/connections.html#buffering)
218
+
connect to MongoDB. Read the [buffering section of the connection docs](./connections.html#buffering)
Copy file name to clipboardExpand all lines: docs/guide.jade
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -694,7 +694,7 @@ block content
694
694
695
695
h4#timestamps option: timestamps
696
696
:markdown
697
-
If set `timestamps`, mongoose assigns `createdAt` and `updatedAt` fields to your schema, the type assigned is [Date](http://mongoosejs.com/docs/api.html#schema-date-js).
697
+
If set `timestamps`, mongoose assigns `createdAt` and `updatedAt` fields to your schema, the type assigned is [Date](./api.html#schema-date-js).
698
698
699
699
By default, the name of two fields are `createdAt` and `updatedAt`, customize the field name by setting `timestamps.createdAt` and `timestamps.updatedAt`.
var organizationSchema = new Schema({ name: String, kind: String });
291
-
291
+
292
292
var User = mongoose.model('User', userSchema);
293
293
var Organization = mongoose.model('Organization', organizationSchema);
294
294
:markdown
@@ -320,17 +320,17 @@ block content
320
320
// doc.connections[0].item is a User doc
321
321
// doc.connections[1].item is an Organization doc
322
322
});
323
-
323
+
324
324
h3#populate-virtuals Populate Virtuals
325
325
:markdown
326
326
_New in 4.5.0_
327
-
327
+
328
328
So far you've only populated based on the `_id` field. However, that's
329
329
sometimes not the right choice.
330
330
In particular, [arrays that grow without bound are a MongoDB anti-pattern](https://docs.mongodb.com/manual/tutorial/model-referenced-one-to-many-relationships-between-documents/).
331
331
Using mongoose virtuals, you can define more sophisticated relationships
332
332
between documents.
333
-
333
+
334
334
:js
335
335
var PersonSchema = new Schema({
336
336
name: String,
@@ -348,10 +348,10 @@ block content
348
348
// an array. `justOne` is false by default.
349
349
justOne: false
350
350
});
351
-
351
+
352
352
var Person = mongoose.model('Person', PersonSchema);
353
353
var Band = mongoose.model('Band', BandSchema);
354
-
354
+
355
355
/**
356
356
* Suppose you have 2 bands: "Guns N' Roses" and "Motley Crue"
357
357
* And 4 people: "Axl Rose" and "Slash" with "Guns N' Roses", and
Copy file name to clipboardExpand all lines: docs/schematypes.jade
+26-26Lines changed: 26 additions & 26 deletions
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ block content
17
17
a(href="./api.html#query-js") queries
18
18
| and other general characteristics for
19
19
a(href="./api.html#schema-string-js") Strings
20
-
| and
20
+
| and
21
21
a(href="./api.html#schema-number-js") Numbers
22
22
|. Check out their respective API documentation for more detail.
23
23
p
@@ -88,7 +88,7 @@ block content
88
88
var schema1 = new Schema({
89
89
test: String // `test` is a path of type String
90
90
});
91
-
91
+
92
92
var schema2 = new Schema({
93
93
test: { type: String } // `test` is a path of type string
94
94
});
@@ -108,14 +108,14 @@ block content
108
108
types.
109
109
h5 All Schema Types
110
110
:markdown
111
-
* `required`: boolean or function, if true adds a [required validator](http://mongoosejs.com/docs/validation.html#built-in-validators) for this property
111
+
* `required`: boolean or function, if true adds a [required validator](./validation.html#built-in-validators) for this property
112
112
* `default`: Any or function, sets a default value for the path. If the value is a function, the return value of the function is used as the default.
113
113
* `select`: boolean, specifies default [projections](https://docs.mongodb.com/manual/tutorial/project-fields-from-query-results/) for queries
114
-
* `validate`: function, adds a [validator function](http://mongoosejs.com/docs/validation.html#built-in-validators) for this property
114
+
* `validate`: function, adds a [validator function](./validation.html#built-in-validators) for this property
115
115
* `get`: function, defines a custom getter for this property using [`Object.defineProperty()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty).
116
116
* `set`: function, defines a custom setter for this property using [`Object.defineProperty()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty).
117
-
* `alias`: string, mongoose >= 4.10.0 only. Defines a [virtual](http://mongoosejs.com/docs/guide.html#virtuals) with the given name that gets/sets this path.
118
-
117
+
* `alias`: string, mongoose >= 4.10.0 only. Defines a [virtual](./guide.html#virtuals) with the given name that gets/sets this path.
118
+
119
119
:js
120
120
var numberSchema = new Schema({
121
121
integerOnly: {
@@ -125,23 +125,23 @@ block content
125
125
alias: 'i'
126
126
}
127
127
});
128
-
128
+
129
129
var Number = mongoose.model('Number', numberSchema);
130
-
130
+
131
131
var doc = new Number();
132
132
doc.integerOnly = 2.001;
133
133
doc.integerOnly; // 2
134
134
doc.i; // 2
135
135
doc.i = 3.001;
136
136
doc.integerOnly; // 3
137
137
doc.i; // 3
138
-
138
+
139
139
h5 Indexes
140
140
p
141
141
:markdown
142
142
You can also define [MongoDB indexes](https://docs.mongodb.com/manual/indexes/)
143
143
using schema type options.
144
-
144
+
145
145
:markdown
146
146
* `index`: boolean, whether to define an [index](https://docs.mongodb.com/manual/indexes/) on this property.
147
147
* `unique`: boolean, whether to define a [unique index](https://docs.mongodb.com/manual/core/index-unique/) on this property.
@@ -160,14 +160,14 @@ block content
160
160
* `lowercase`: boolean, whether to always call `.toLowerCase()` on the value
161
161
* `uppercase`: boolean, whether to always call `.toUpperCase()` on the value
162
162
* `trim`: boolean, whether to always call `.trim()` on the value
163
-
* `match`: RegExp, creates a [validator](http://mongoosejs.com/docs/validation.html) that checks if the value matches the given regular expression
164
-
* `enum`: Array, creates a [validator](http://mongoosejs.com/docs/validation.html) that checks if the value is in the given array.
163
+
* `match`: RegExp, creates a [validator](./validation.html) that checks if the value matches the given regular expression
164
+
* `enum`: Array, creates a [validator](./validation.html) that checks if the value is in the given array.
165
165
166
166
h5 Number
167
167
:markdown
168
-
* `min`: Number, creates a [validator](http://mongoosejs.com/docs/validation.html) that checks if the value is greater than or equal to the given minimum.
169
-
* `max`: Number, creates a [validator](http://mongoosejs.com/docs/validation.html) that checks if the value is less than or equal to the given maximum.
170
-
168
+
* `min`: Number, creates a [validator](./validation.html) that checks if the value is greater than or equal to the given minimum.
169
+
* `max`: Number, creates a [validator](./validation.html) that checks if the value is less than or equal to the given maximum.
170
+
171
171
h5 Date
172
172
:markdown
173
173
* `min`: Date
@@ -195,7 +195,7 @@ block content
195
195
var Any = new Schema({ any: Object });
196
196
var Any = new Schema({ any: Schema.Types.Mixed });
197
197
p
198
-
| Since it is a schema-less type, you can change the value to anything else you like, but Mongoose loses the ability to auto detect and save those changes. To "tell" Mongoose that the value of a Mixed type has changed, call the
198
+
| Since it is a schema-less type, you can change the value to anything else you like, but Mongoose loses the ability to auto detect and save those changes. To "tell" Mongoose that the value of a Mixed type has changed, call the
199
199
code .markModified(path)
200
200
| method of the document passing the path to the Mixed type you just changed.
201
201
:js
@@ -204,7 +204,7 @@ block content
204
204
person.save(); // anything will now get saved
205
205
h4#objectids ObjectIds
206
206
p
207
-
| To specify a type of ObjectId, use
207
+
| To specify a type of ObjectId, use
208
208
code Schema.Types.ObjectId
209
209
| in your declaration.
210
210
:js
@@ -214,9 +214,9 @@ block content
214
214
// or just Schema.ObjectId for backwards compatibility with v2
0 commit comments