Skip to content

Commit

Permalink
docs: fix links in 4.x docs
Browse files Browse the repository at this point in the history
Fix #6081
  • Loading branch information
vkarpov15 committed Feb 7, 2018
1 parent 6d2963c commit 3660092
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 66 deletions.
4 changes: 2 additions & 2 deletions docs/connections.jade
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ block content
}, 60000);

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

Expand Down Expand Up @@ -92,7 +92,7 @@ block content

h3#callback Callback
:markdown
The `connect()` function also accepts a callback parameter and returns a [promise](http://mongoosejs.com/docs/promises.html).
The `connect()` function also accepts a callback parameter and returns a [promise](./promises.html).
:js
mongoose.connect(uri, options, function(error) {
// Check error in initial connection. There is no 2nd param to the callback.
Expand Down
6 changes: 3 additions & 3 deletions docs/documents.jade
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ block content
});
});
:markdown
You can also use [`.set()`](http://mongoosejs.com/docs/api.html#document_Document-set)
You can also use [`.set()`](./api.html#document_Document-set)
to modify documents. Under the hood, `tank.size = 'large';` becomes `tank.set({ size: 'large' })`.
:js
Tank.findById(id, function (err, tank) {
Expand Down Expand Up @@ -51,7 +51,7 @@ block content
});
:markdown
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.

_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._

h3 Validating
Expand All @@ -61,7 +61,7 @@ block content
h3 Overwriting
:markdown
You can overwrite an entire document using `.set()`. This is handy if you
want to change what document is being saved in [middleware](http://mongoosejs.com/docs/middleware.html).
want to change what document is being saved in [middleware](./docs/middleware.html).
:js
Tank.findById(id, function (err, tank) {
if (err) return handleError(err);
Expand Down
8 changes: 4 additions & 4 deletions docs/faq.jade
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ block content
:markdown
**A**. This is a performance optimization. These empty objects are not saved
to the database, nor are they in the result `toObject()`, nor do they show
up in `JSON.stringify()` output unless you turn off the [`minimize` option](http://mongoosejs.com/docs/guide.html#minimize).
up in `JSON.stringify()` output unless you turn off the [`minimize` option](./guide.html#minimize).

The reason for this behavior is that Mongoose's change detection
and getters/setters are based on [`Object.defineProperty()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty).
Expand All @@ -104,11 +104,11 @@ block content
mongoose defines properties on the `Model` prototype when the model is compiled.
Because mongoose needs to define getters and setters for `nested.prop`, `nested`
must always be defined as an object on a mongoose document, even if `nested`
is undefined on the underlying [POJO](http://mongoosejs.com/docs/guide.html#minimize).
is undefined on the underlying [POJO](./guide.html#minimize).

hr#arrow-functions
:markdown
**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.
**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.

**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).
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.
Expand Down Expand Up @@ -215,7 +215,7 @@ block content
**Q**. All function calls on my models hang, what am I doing wrong?

**A**. By default, mongoose will buffer your function calls until it can
connect to MongoDB. Read the [buffering section of the connection docs](http://mongoosejs.com/docs/connections.html#buffering)
connect to MongoDB. Read the [buffering section of the connection docs](./connections.html#buffering)
for more information.

hr#enable_debugging
Expand Down
2 changes: 1 addition & 1 deletion docs/guide.jade
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ block content

h4#timestamps option: timestamps
:markdown
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).
If set `timestamps`, mongoose assigns `createdAt` and `updatedAt` fields to your schema, the type assigned is [Date](./api.html#schema-date-js).

By default, the name of two fields are `createdAt` and `updatedAt`, customize the field name by setting `timestamps.createdAt` and `timestamps.updatedAt`.
:js
Expand Down
4 changes: 2 additions & 2 deletions docs/middleware.jade
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ block content

Aggregate middleware is for `MyModel.aggregate()`. Aggregate middleware
executes when you call `exec()` on an aggregate object.
In aggregate middleware, `this` refers to the [aggregation object](http://mongoosejs.com/docs/api.html#model_Model.aggregate).
In aggregate middleware, `this` refers to the [aggregation object](./api.html#model_Model.aggregate).

* [aggregate](http://mongoosejs.com/docs/api.html#model_Model.aggregate)
* [aggregate](./api.html#model_Model.aggregate)

Model middleware is supported for the following model functions.
In model middleware functions, `this` refers to the model.
Expand Down
30 changes: 15 additions & 15 deletions docs/populate.jade
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ block content
populate them using the [Model.populate()](./api.html#model_Model.populate)
method available in **mongoose >= 3.6**. This is what `document#populate()`
and `query#populate()` use to populate documents.

h3#deep-populate Populating across multiple levels
:markdown
Say you have a user schema which keeps track of the user's friends.
Expand All @@ -235,7 +235,7 @@ block content
// Get friends of friends - populate the 'friends' array for every friend
populate: { path: 'friends' }
});

h3#cross-db-populate Populating across Databases
:markdown
Let's say you have a schema representing events, and a schema representing
Expand All @@ -256,14 +256,14 @@ block content
:js
var db1 = mongoose.createConnection('localhost:27000/db1');
var db2 = mongoose.createConnection('localhost:27001/db2');

var Event = db1.model('Event', eventSchema);
var Conversation = db2.model('Conversation', conversationSchema);
:markdown
In this situation, you will **not** be able to `populate()` normally.
The `conversation` field will always be null, because `populate()` doesn't
know which model to use. However,
[you can specify the model explicitly](http://mongoosejs.com/docs/api.html#model_Model.populate).
[you can specify the model explicitly](./api.html#model_Model.populate).
:js
Event.
find().
Expand All @@ -286,9 +286,9 @@ block content
item: { type: ObjectId, refPath: 'connections.kind' }
}]
});

var organizationSchema = new Schema({ name: String, kind: String });

var User = mongoose.model('User', userSchema);
var Organization = mongoose.model('Organization', organizationSchema);
:markdown
Expand Down Expand Up @@ -320,17 +320,17 @@ block content
// doc.connections[0].item is a User doc
// doc.connections[1].item is an Organization doc
});

h3#populate-virtuals Populate Virtuals
:markdown
_New in 4.5.0_

So far you've only populated based on the `_id` field. However, that's
sometimes not the right choice.
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/).
Using mongoose virtuals, you can define more sophisticated relationships
between documents.

:js
var PersonSchema = new Schema({
name: String,
Expand All @@ -348,10 +348,10 @@ block content
// an array. `justOne` is false by default.
justOne: false
});

var Person = mongoose.model('Person', PersonSchema);
var Band = mongoose.model('Band', BandSchema);

/**
* Suppose you have 2 bands: "Guns N' Roses" and "Motley Crue"
* And 4 people: "Axl Rose" and "Slash" with "Guns N' Roses", and
Expand All @@ -360,24 +360,24 @@ block content
Band.find({}).populate('members').exec(function(error, bands) {
/* `bands.members` is now an array of instances of `Person` */
});

:markdown
Keep in mind that virtuals are _not_ included in `toJSON()` output by
default. If you want populate virtuals to show up when using functions
that rely on `JSON.stringify()`, like Express'
[`res.json()` function](http://expressjs.com/en/4x/api.html#res.json),
set the `virtuals: true` option on your schema's `toJSON` options.

:js
// Set `virtuals: true` so `res.json()` works
var BandSchema = new Schema({
name: String
}, { toJSON: { virtuals: true } });

:markdown
If you're using populate projections, make sure `foreignField` is included
in the projection.

:js
Band.
find({}).
Expand Down
10 changes: 5 additions & 5 deletions docs/queries.jade
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ block content
})
:markdown
Here we see that the query was executed immediately and the results passed to our callback. All callbacks in Mongoose use the pattern:
`callback(error, result)`. If an error occurs executing the query, the `error` parameter will contain an error document, and `result`
`callback(error, result)`. If an error occurs executing the query, the `error` parameter will contain an error document, and `result`
will be null. If the query is successful, the `error` parameter will be null, and the `result` will be populated with the results of the query.
.important
:markdown
Expand Down Expand Up @@ -77,24 +77,24 @@ block content
exec(callback);

:markdown
A full list of [Query helper functions can be found in the API docs](http://mongoosejs.com/docs/api.html#query-js).
A full list of [Query helper functions can be found in the API docs](./api.html#query-js).

h3#setters
:markdown
Setters are not executed by default in 4.x. For example, if you lowercase emails in your schema:

:js
var personSchema = new Schema({
email: {
type: String,
lowercase: true
}
});

:markdown
Mongoose will **not** automatically lowercase the email in your queries, so `Person.find({ email: '[email protected]' })` would return no results.
Use the `runSettersOnQuery` option to turn on this behavior:

:js
var personSchema = new Schema({
email: {
Expand Down
52 changes: 26 additions & 26 deletions docs/schematypes.jade
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ block content
a(href="./api.html#query-js") queries
| and other general characteristics for 
a(href="./api.html#schema-string-js") Strings
| and
| and
a(href="./api.html#schema-number-js") Numbers
|. Check out their respective API documentation for more detail.
p
Expand Down Expand Up @@ -88,7 +88,7 @@ block content
var schema1 = new Schema({
test: String // `test` is a path of type String
});

var schema2 = new Schema({
test: { type: String } // `test` is a path of type string
});
Expand All @@ -108,14 +108,14 @@ block content
types.
h5 All Schema Types
:markdown
* `required`: boolean or function, if true adds a [required validator](http://mongoosejs.com/docs/validation.html#built-in-validators) for this property
* `required`: boolean or function, if true adds a [required validator](./validation.html#built-in-validators) for this property
* `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.
* `select`: boolean, specifies default [projections](https://docs.mongodb.com/manual/tutorial/project-fields-from-query-results/) for queries
* `validate`: function, adds a [validator function](http://mongoosejs.com/docs/validation.html#built-in-validators) for this property
* `validate`: function, adds a [validator function](./validation.html#built-in-validators) for this property
* `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).
* `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).
* `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.
* `alias`: string, mongoose >= 4.10.0 only. Defines a [virtual](./guide.html#virtuals) with the given name that gets/sets this path.

:js
var numberSchema = new Schema({
integerOnly: {
Expand All @@ -125,23 +125,23 @@ block content
alias: 'i'
}
});

var Number = mongoose.model('Number', numberSchema);

var doc = new Number();
doc.integerOnly = 2.001;
doc.integerOnly; // 2
doc.i; // 2
doc.i = 3.001;
doc.integerOnly; // 3
doc.i; // 3

h5 Indexes
p
:markdown
You can also define [MongoDB indexes](https://docs.mongodb.com/manual/indexes/)
using schema type options.

:markdown
* `index`: boolean, whether to define an [index](https://docs.mongodb.com/manual/indexes/) on this property.
* `unique`: boolean, whether to define a [unique index](https://docs.mongodb.com/manual/core/index-unique/) on this property.
Expand All @@ -160,14 +160,14 @@ block content
* `lowercase`: boolean, whether to always call `.toLowerCase()` on the value
* `uppercase`: boolean, whether to always call `.toUpperCase()` on the value
* `trim`: boolean, whether to always call `.trim()` on the value
* `match`: RegExp, creates a [validator](http://mongoosejs.com/docs/validation.html) that checks if the value matches the given regular expression
* `enum`: Array, creates a [validator](http://mongoosejs.com/docs/validation.html) that checks if the value is in the given array.
* `match`: RegExp, creates a [validator](./validation.html) that checks if the value matches the given regular expression
* `enum`: Array, creates a [validator](./validation.html) that checks if the value is in the given array.

h5 Number
:markdown
* `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.
* `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.
* `min`: Number, creates a [validator](./validation.html) that checks if the value is greater than or equal to the given minimum.
* `max`: Number, creates a [validator](./validation.html) that checks if the value is less than or equal to the given maximum.

h5 Date
:markdown
* `min`: Date
Expand Down Expand Up @@ -195,7 +195,7 @@ block content
var Any = new Schema({ any: Object });
var Any = new Schema({ any: Schema.Types.Mixed });
p
| 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
| 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
code .markModified(path)
| method of the document passing the path to the Mixed type you just changed.
:js
Expand All @@ -204,7 +204,7 @@ block content
person.save(); // anything will now get saved
h4#objectids ObjectIds
p
| To specify a type of ObjectId, use
| To specify a type of ObjectId, use
code Schema.Types.ObjectId
| in your declaration.
:js
Expand All @@ -214,9 +214,9 @@ block content
// or just Schema.ObjectId for backwards compatibility with v2
h4#arrays Arrays
p
| Provide creation of arrays of
| Provide creation of arrays of
a(href="./api.html#schema_Schema.Types") SchemaTypes
| or
| or
a(href="./subdocs.html") Sub-Documents
|.
:js
Expand All @@ -229,9 +229,9 @@ block content
// ... etc
});
p
| Note: specifying an empty array is equivalent to
| Note: specifying an empty array is equivalent to
code Mixed
|. The following all create arrays of
|. The following all create arrays of
code Mixed
|:
:js
Expand Down Expand Up @@ -268,18 +268,18 @@ block content
});
h3#customtypes Creating Custom Types
p
| Mongoose can also be extended with custom SchemaTypes. Search the
| Mongoose can also be extended with custom SchemaTypes. Search the
a(href="http://plugins.mongoosejs.com") plugins
| site for compatible types like
| site for compatible types like
a(href="https://github.com/aheckmann/mongoose-long") mongoose-long
| , 
a(href="https://github.com/vkarpov15/mongoose-int32") mongoose-int32
| and
| and
a(href="https://github.com/aheckmann/mongoose-function") other
|
|
a(href="https://github.com/OpenifyIt/mongoose-types") types
|.

h3#path The `schema.path()` Function
:markdown
The `schema.path()` function returns the instantiated schema type for a
Expand Down
Loading

0 comments on commit 3660092

Please sign in to comment.