Creating from ES6 Classes Using loadClass()
-
loadClass()
Mongoose allows creating schemas from ES6 classes. +
Creating from ES6 Classes Using loadClass()
Mongoose allows creating schemas from ES6 classes.
The loadClass()
function lets you pull in methods,
statics, and virtuals from an ES6 class. A class method maps to a schema
method, a static method maps to a schema static, and getters/setters map
diff --git a/docs/api.html b/docs/api.html
index 14cea2fee8..04c967feea 100644
--- a/docs/api.html
+++ b/docs/api.html
@@ -1,4 +1,4 @@
-
API Docs
API Docs
Index
- Mongoose()
- Mongoose.prototype.Aggregate()
- Mongoose.prototype.CastError()
- Mongoose.prototype.Collection()
- Mongoose.prototype.Connection()
- Mongoose.prototype.Decimal128
- Mongoose.prototype.Document()
- Mongoose.prototype.DocumentProvider()
- Mongoose.prototype.Error()
- Mongoose.prototype.Mixed
- Mongoose.prototype.Model()
- Mongoose.prototype.Mongoose()
- Mongoose.prototype.Number
- Mongoose.prototype.ObjectId
- Mongoose.prototype.Promise
- Mongoose.prototype.PromiseProvider()
- Mongoose.prototype.Query()
- Mongoose.prototype.STATES
- Mongoose.prototype.Schema()
- Mongoose.prototype.SchemaType()
- Mongoose.prototype.SchemaTypes
- Mongoose.prototype.Types
- Mongoose.prototype.VirtualType()
- Mongoose.prototype.connect()
- Mongoose.prototype.connection
- Mongoose.prototype.connections
- Mongoose.prototype.createConnection()
- Mongoose.prototype.deleteModel()
- Mongoose.prototype.disconnect()
- Mongoose.prototype.get()
- Mongoose.prototype.model()
- Mongoose.prototype.modelNames()
- Mongoose.prototype.mongo
- Mongoose.prototype.mquery
- Mongoose.prototype.now()
- Mongoose.prototype.plugin()
- Mongoose.prototype.pluralize()
- Mongoose.prototype.set()
- Mongoose.prototype.startSession()
- Mongoose.prototype.version
Mongoose()
Type:
- «function»
Mongoose constructor.
diff --git a/docs/browser.html b/docs/browser.html index b8c9b42ec5..8fbdf0b4f8 100644 --- a/docs/browser.html +++ b/docs/browser.html @@ -1,4 +1,4 @@ -Mongoose in the Browser
+Mongoose in the Browser
Mongoose supports creating schemas and validating documents in the browser. Mongoose's browser library does not support saving documents, queries, @@ -12,6 +12,12 @@ // Using ES6 imports import mongoose from 'mongoose/browser'; +
+ +Using the Browser Library
Mongoose's browser library is very limited. The only use case it supports diff --git a/docs/compatibility.html b/docs/compatibility.html index 0fdfb97c47..2ed8788bdd 100644 --- a/docs/compatibility.html +++ b/docs/compatibility.html @@ -1,4 +1,4 @@ -
MongoDB Server Version Compatibility
+MongoDB Server Version Compatibility
Connections
+Contributing
+Contributing
Please read all about contributing here.
Creating a Basic Custom Schema Type
-
New in Mongoose 4.4.0: Mongoose supports custom types. Before you +
Creating a Basic Custom Schema Type
New in Mongoose 4.4.0: Mongoose supports custom types. Before you reach for a custom type, however, know that a custom type is overkill for most use cases. You can do most basic tasks with custom getters/setters, diff --git a/docs/defaults.html b/docs/defaults.html index d20e158506..ea57a21aa5 100644 --- a/docs/defaults.html +++ b/docs/defaults.html @@ -1,5 +1,4 @@ -
Declaring defaults in your schema
-
Your schemas can define default values for certain paths. If you create +
- Declaring defaults in your schema
- Default functions
- The
setDefaultsOnInsert
option - Default functions and
this
Declaring defaults in your schema
Your schemas can define default values for certain paths. If you create a new document without that path set, the default will kick in.
Note: Mongoose only applies a default if the value of the path is
strictly undefined
.
Default functions
-
You can also set the default
schema option to a function. Mongoose will
+
Default functions
You can also set the default
schema option to a function. Mongoose will
execute that function and use the return value as the default.
var schema = new Schema({
@@ -54,8 +52,7 @@ Default functions
assert.ok(post.date.getTime() >= Date.now() - 1000);
assert.ok(post.date.getTime() <= Date.now());
-The setDefaultsOnInsert
option
-
setDefaultsOnInsert
optionBy default, mongoose only applies defaults when you create a new document. +
The setDefaultsOnInsert
option
By default, mongoose only applies defaults when you create a new document.
It will not set defaults if you use update()
and
findOneAndUpdate()
. However, mongoose 4.x lets you opt-in to this
behavior using the setDefaultsOnInsert
option.
Important
assert.equal(doc.genre, 'Action'); }); -Default functions and this
-
this
Unless it is running on a query with setDefaultsOnInsert
, a default
+
Default functions and this
Unless it is running on a query with setDefaultsOnInsert
, a default
function's this
refers to the document.
const schema = new Schema({
diff --git a/docs/deprecations.html b/docs/deprecations.html
index c22785e405..cae5a98e89 100644
--- a/docs/deprecations.html
+++ b/docs/deprecations.html
@@ -1,4 +1,4 @@
-Mongoose v5.4.7-pre: Deprecation Warnings Deprecation Warnings
+Mongoose v5.4.9-pre: Deprecation Warnings Deprecation Warnings
The model.discriminator()
function
-
Discriminators are a schema inheritance mechanism. They enable
+
Mongoose v5.4.9-pre: Discriminators - The
model.discriminator()
function - Discriminators save to the Event model's collection
- Discriminator keys
- Discriminators add the discriminator key to queries
- Discriminators copy pre and post hooks
- Handling custom _id fields
- Using discriminators with
Model.create()
- Embedded discriminators in arrays
- Recursive embedded discriminators in arrays
The model.discriminator()
function
Discriminators are a schema inheritance mechanism. They enable
you to have multiple models with overlapping schemas on top of the
same underlying MongoDB collection.
Suppose you wanted to track different types of events in a single
@@ -29,8 +28,7 @@
new ClickedLinkEvent({time: Date.now(), url: 'google.com'});
assert.ok(clickedEvent.url);
-
Discriminators save to the Event model's collection
-
Suppose you created another discriminator to track events where
+
Discriminators save to the Event model's collection
Suppose you created another discriminator to track events where
a new user registered. These SignedUpEvent
instances will be
stored in the same collection as generic events and ClickedLinkEvent
instances.
@@ -52,8 +50,7 @@ Discriminator keys
-
The way mongoose tells the difference between the different
+
Discriminator keys
The way mongoose tells the difference between the different
discriminator models is by the 'discriminator key', which is
__t
by default. Mongoose adds a String path called __t
to your schemas that it uses to track which discriminator
@@ -67,8 +64,7 @@
Discriminator keys<
assert.equal(event2.__t, 'ClickedLink');
assert.equal(event3.__t, 'SignedUp');
-
Discriminators add the discriminator key to queries
-
Discriminator models are special; they attach the discriminator key
+
Discriminators add the discriminator key to queries
Discriminator models are special; they attach the discriminator key
to queries. In other words, find()
, count()
, aggregate()
, etc.
are smart enough to account for discriminators.
@@ -91,8 +87,7 @@ Discriminators copy pre and post hooks
-
Discriminators also take their base schema's pre and post middleware.
+
Discriminators copy pre and post hooks
Discriminators also take their base schema's pre and post middleware.
However, you can also attach middleware to the discriminator schema
without affecting the base schema.
@@ -127,8 +122,7 @@ Handling custom _id fields
-
A discriminator's fields are the union of the base schema's fields and
+
Handling custom _id fields
A discriminator's fields are the union of the base schema's fields and
the discriminator schema's fields, and the discriminator schema's fields
take precedence. There is one exception: the default _id
field.
You can work around this by setting the _id
option to false in the
@@ -158,8 +152,7 @@
Han
assert.ok(typeof event1._id === 'string');
assert.ok(typeof event1.time === 'string');
-
Using discriminators with Model.create()
-
When you use Model.create()
, mongoose will pull the correct type from
+
Using discriminators with Model.create()
When you use Model.create()
, mongoose will pull the correct type from
the discriminator key for you.
var Schema = mongoose.Schema;
@@ -188,8 +181,7 @@ 2].side, 10);
});
-Embedded discriminators in arrays
-
You can also define discriminators on embedded document arrays.
+
Embedded discriminators in arrays
You can also define discriminators on embedded document arrays.
Embedded discriminators are different because the different discriminator
types are stored in the same document array (within a document) rather
than the same collection. In other words, embedded discriminators let
@@ -261,8 +253,7 @@
catch(done);
-Recursive embedded discriminators in arrays
-
You can also define embedded discriminators on embedded discriminators.
+
Recursive embedded discriminators in arrays
You can also define embedded discriminators on embedded discriminators.
In the below example, sub_events
is an embedded discriminator, and
for sub_event
keys with value 'SubEvent', sub_events.events
is an
embedded discriminator.
diff --git a/docs/documents.html b/docs/documents.html
index 52c18d0fe2..9d1aa4821e 100644
--- a/docs/documents.html
+++ b/docs/documents.html
@@ -1,4 +1,4 @@
-Mongoose v5.4.7-pre: Documents Documents
+Mongoose v5.4.9-pre: Documents Documents
FAQ
+FAQ
Further Reading
+Further Reading
Using GeoJSON
+Mongoose v5.4.9-pre: Using GeoJSON Using GeoJSON
GeoJSON is a format for storing geographic points and
polygons. MongoDB has excellent support for geospatial queries
on GeoJSON objects. Let's take a look at how you can use Mongoose to store
diff --git a/docs/guide.html b/docs/guide.html
index f040182f51..4b76c3daf7 100644
--- a/docs/guide.html
+++ b/docs/guide.html
@@ -1,4 +1,4 @@
-
Mongoose v5.4.7-pre: Schemas Schemas
+Mongoose v5.4.9-pre: Schemas Schemas
Guides
+Mongoose v5.4.9-pre: Schemas Guides
Mongoose guides provide detailed tutorials on Mongoose's core concepts and
integrating Mongoose with external tools and frameworks.
Mongoose Core Concepts
diff --git a/docs/index.html b/docs/index.html
index 41dc899b6f..dfc8fdb7d6 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -1,4 +1,4 @@
-Mongoose v5.4.7-pre: Getting Started Getting Started
+Getting Started
First be sure you have MongoDB and Node.js installed.
Next install Mongoose from the command line using npm
:
$ npm install mongoose
diff --git a/docs/jest.html b/docs/jest.html
index 7aee213ec2..2b5b0bb361 100644
--- a/docs/jest.html
+++ b/docs/jest.html
@@ -1,4 +1,4 @@
-Mongoose v5.4.7-pre: Testing Mongoose with Jest Testing Mongoose with Jest
+Mongoose v5.4.9-pre: Testing Mongoose with Jest Testing Mongoose with Jest
Jest is a client-side JavaScript testing library developed by Facebook.
It was one of the libraries affected by Facebook's licensing scandal in 2017.
Because Jest is designed primarily for testing React applications, using
diff --git a/docs/lambda.html b/docs/lambda.html
index 05ac644e5c..b823717ce5 100644
--- a/docs/lambda.html
+++ b/docs/lambda.html
@@ -1,4 +1,4 @@
-
Mongoose v5.4.7-pre: Using Mongoose With AWS Lambda Using Mongoose With AWS Lambda
AWS Lambda is a popular service for running
+
Mongoose v5.4.9-pre: Using Mongoose With AWS Lambda Using Mongoose With AWS Lambda
AWS Lambda is a popular service for running
arbitrary functions without managing individual servers. Using Mongoose in your
AWS Lambda functions is easy. Here's a sample function that connects to a
MongoDB instance and finds a single document:
diff --git a/docs/middleware.html b/docs/middleware.html
index 0de44799e9..c3358caaaa 100644
--- a/docs/middleware.html
+++ b/docs/middleware.html
@@ -1,4 +1,4 @@
-Mongoose v5.4.7-pre: Middleware Middleware
+Mongoose v5.4.9-pre: Middleware Middleware
Migrating from 4.x to 5.x
+Migrating from 4.x to 5.x
Migrating from 3.x to 4.x
There are several backwards-breaking changes to be aware of when migrating from Mongoose 3 to Mongoose 4.
+Migrating from 3.x to 4.x
There are several backwards-breaking changes to be aware of when migrating from Mongoose 3 to Mongoose 4.
findOneAndUpdate()
new field is now false
by default
Mongoose's findOneAndUpdate()
, findOneAndRemove()
,
diff --git a/docs/models.html b/docs/models.html
index 669e18be54..fa23ef7f8c 100644
--- a/docs/models.html
+++ b/docs/models.html
@@ -1,4 +1,4 @@
-
Mongoose v5.4.7-pre: Models Models
+Mongoose v5.4.9-pre: Models Models
Plugins
+Mongoose v5.4.9-pre: Plugins Plugins
Built-in Promises
-
Mongoose async operations, like .save()
and queries, return thenables.
+
Mongoose v5.4.9-pre: Promises Built-in Promises
Mongoose async operations, like .save()
and queries, return thenables.
This means that you can do things like MyModel.findOne({}).then()
and
await MyModel.findOne({}).exec()
if you're using
async/await.
@@ -17,8 +16,7 @@
assert.equal(doc.name, "Guns N' Roses");
});
-Queries are not promises
-
Mongoose queries are not promises. They have a .then()
+
Queries are not promises
Mongoose queries are not promises. They have a .then()
function for co and async/await as
a convenience. If you need
a fully-fledged promise, use the .exec()
function.
@@ -39,8 +37,7 @@ Queries
// use doc
});
-
Plugging in your own Promises Library
-
If you're an advanced user, you may want to plug in your own promise
+
Plugging in your own Promises Library
If you're an advanced user, you may want to plug in your own promise
library like bluebird. Just set
mongoose.Promise
to your favorite
ES6-style promise constructor and mongoose will use it.
diff --git a/docs/queries.html b/docs/queries.html
index c293b9dd8b..b03e19470b 100644
--- a/docs/queries.html
+++ b/docs/queries.html
@@ -1,4 +1,4 @@
-Mongoose v5.4.7-pre: Queries Queries
+Mongoose v5.4.9-pre: Queries Queries
SchemaTypes
+Mongoose v5.4.9-pre: SchemaTypes SchemaTypes
Subdocuments
+Mongoose v5.4.9-pre: SubDocuments Subdocuments
Transactions in Mongoose
+Mongoose v5.4.9-pre: Transactions Transactions in Mongoose
Transactions are new in MongoDB
4.0 and Mongoose 5.2.0. Transactions let you execute multiple operations
in isolation and potentially undo all the operations if one of them fails.
diff --git a/docs/validation.html b/docs/validation.html
index 3473f0b237..56af44785a 100644
--- a/docs/validation.html
+++ b/docs/validation.html
@@ -1,5 +1,4 @@
-
Mongoose v5.4.7-pre: Validation Validation
-
Before we get into the specifics of validation syntax, please keep the following rules in mind:
+Mongoose v5.4.9-pre: Validation - Validation
- Built-in Validators
- The
unique
Option is Not a Validator - Custom Validators
- Async Custom Validators
- Validation Errors
- Required Validators On Nested Objects
- Update Validators
- Update Validators and
this
- The
context
option - Update Validators Only Run On Updated Paths
- Update Validators Only Run For Some Operations
- On $push and $addToSet
Validation
Before we get into the specifics of validation syntax, please keep the following rules in mind:
- Validation is defined in the SchemaType
- Validation is middleware. Mongoose registers validation as a
pre('save')
hook on every schema by default.
@@ -28,8 +27,7 @@
'Path `name` is required.');
});
-Built-in Validators
-
Mongoose has several built-in validators.
+Built-in Validators
Mongoose has several built-in validators.
- All SchemaTypes have the built-in required validator. The required validator uses the SchemaType's
checkRequired()
function to determine if the value satisfies the required validator.
- Numbers have
min
and max
validators.
@@ -79,8 +77,7 @@ Built-in Validato
error = badBreakfast.validateSync();
assert.equal(error.errors['bacon'].message, 'Why no bacon?');
-
The unique
Option is Not a Validator
-
A common gotcha for beginners is that the unique
option for schemas
+
The unique
Option is Not a Validator
A common gotcha for beginners is that the unique
option for schemas
is not a validator. It's a convenient helper for building MongoDB unique indexes.
See the FAQ for more information.
@@ -125,8 +122,7 @@ Custom Validators
-
If the built-in validators aren't enough, you can define custom validators
+
Custom Validators
If the built-in validators aren't enough, you can define custom validators
to suit your needs.
Custom validation is declared by passing a validation function.
You can find detailed instructions on how to do this in the
@@ -165,8 +161,7 @@
Custom Validators
error = user.validateSync();
assert.equal(error, null);
-Async Custom Validators
-
Custom validators can also be asynchronous. If your validator function
+
Async Custom Validators
Custom validators can also be asynchronous. If your validator function
returns a promise (like an async
function), mongoose will wait for that
promise to settle. If you prefer callbacks, set the isAsync
option,
and mongoose will pass a callback as the 2nd argument to your validator
@@ -219,8 +214,7 @@
Async Cus
'Validator failed for path `name` with value `test`');
});
-
Validation Errors
-
Errors returned after failed validation contain an errors
object
+
Validation Errors
Errors returned after failed validation contain an errors
object
whose values are ValidatorError
objects. Each
ValidatorError has kind
, path
,
value
, and message
properties.
@@ -271,8 +265,7 @@
Validation Errors
assert.equal(err.name, 'ValidationError');
});
-Required Validators On Nested Objects
-
Defining validators on nested objects in mongoose is tricky, because
+
Required Validators On Nested Objects
Defining validators on nested objects in mongoose is tricky, because
nested objects are not fully fledged paths.
var personSchema = new Schema({
@@ -306,8 +299,7 @@ var error = person.validateSync();
assert.ok(error.errors['name']);
-Update Validators
-
In the above examples, you learned about document validation. Mongoose also
+
Update Validators
In the above examples, you learned about document validation. Mongoose also
supports validation for update()
and findOneAndUpdate()
operations.
Update validators are off by default - you need to specify
the runValidators
option.
@@ -332,8 +324,7 @@ Update Validators
'Invalid color');
});
-Update Validators and this
-
There are a couple of key differences between update validators and
+
Update Validators and this
There are a couple of key differences between update validators and
document validators. In the color validation function above, this
refers
to the document being validated when using document validation.
However, when running update validators, the document being updated
@@ -372,8 +363,7 @@
Upd
assert.ok(error);
});
-
The context
option
-
The context
option lets you set the value of this
in update validators
+
The context
option
The context
option lets you set the value of this
in update validators
to the underlying query.
toySchema.path('color').validate(function(value) {
@@ -395,8 +385,7 @@ The context
assert.ok(error.errors['color']);
});
-Update Validators Only Run On Updated Paths
-
The other key difference that update validators only run on the paths
+
Update Validators Only Run On Updated Paths
The other key difference that update validators only run on the paths
specified in the update. For instance, in the below example, because
'name' is not specified in the update operation, update validation will
succeed.
@@ -423,8 +412,7 @@ 'name']);
});
-Update Validators Only Run For Some Operations
-
One final detail worth noting: update validators only run on the
+
Update Validators Only Run For Some Operations
One final detail worth noting: update validators only run on the
following update operators:
$set
@@ -464,8 +452,7 @@ On $push and $addToSet
-
New in 4.8.0: update validators also run on $push
and $addToSet
+On $push and $addToSet
New in 4.8.0: update validators also run on $push
and $addToSet
var testSchema = new Schema({
numbers: [{ type: Number, max: 0 }],
diff --git a/index.html b/index.html
index 932a316bdb..01b0f7627b 100644
--- a/index.html
+++ b/index.html
@@ -1,4 +1,4 @@
-Mongoose ODM v5.4.7-pre 
- Version 5.4.7-pre
Let's face it, writing MongoDB validation, casting and business logic boilerplate is a drag. That's why we wrote Mongoose.
const mongoose = require('mongoose');
+
- Version 5.4.9-pre
Let's face it, writing MongoDB validation, casting and business logic boilerplate is a drag. That's why we wrote Mongoose.
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost:27017/test', {useNewUrlParser: true});
const Cat = mongoose.model('Cat', { name: String });
@@ -115,6 +115,12 @@ Sponsors
+
+
+
+
+
+
diff --git a/index.jade b/index.jade
index 281c321646..316244a81a 100644
--- a/index.jade
+++ b/index.jade
@@ -171,6 +171,12 @@ html(lang='en')
+
+
+
+
+
+