Cleanup
This commit is contained in:
143
node_modules/mongoose/lib/index.js
generated
vendored
143
node_modules/mongoose/lib/index.js
generated
vendored
@@ -16,6 +16,7 @@ if (global.MONGOOSE_DRIVER_PATH) {
|
||||
}
|
||||
|
||||
const Document = require('./document');
|
||||
const EventEmitter = require('events').EventEmitter;
|
||||
const Schema = require('./schema');
|
||||
const SchemaType = require('./schematype');
|
||||
const SchemaTypes = require('./schema/index');
|
||||
@@ -26,6 +27,7 @@ const Types = require('./types');
|
||||
const Query = require('./query');
|
||||
const Model = require('./model');
|
||||
const applyPlugins = require('./helpers/schema/applyPlugins');
|
||||
const driver = require('./driver');
|
||||
const get = require('./helpers/get');
|
||||
const promiseOrCallback = require('./helpers/promiseOrCallback');
|
||||
const legacyPluralize = require('mongoose-legacy-pluralize');
|
||||
@@ -34,6 +36,7 @@ const pkg = require('../package.json');
|
||||
const cast = require('./cast');
|
||||
const removeSubdocs = require('./plugins/removeSubdocs');
|
||||
const saveSubdocs = require('./plugins/saveSubdocs');
|
||||
const trackTransaction = require('./plugins/trackTransaction');
|
||||
const validateBeforeSave = require('./plugins/validateBeforeSave');
|
||||
|
||||
const Aggregate = require('./aggregate');
|
||||
@@ -64,9 +67,12 @@ function Mongoose(options) {
|
||||
this.connections = [];
|
||||
this.models = {};
|
||||
this.modelSchemas = {};
|
||||
this.events = new EventEmitter();
|
||||
// default global options
|
||||
this.options = Object.assign({
|
||||
pluralization: true
|
||||
pluralization: true,
|
||||
autoIndex: true,
|
||||
useCreateIndex: false
|
||||
}, options);
|
||||
const conn = this.createConnection(); // default connection
|
||||
conn.models = this.models;
|
||||
@@ -106,7 +112,8 @@ function Mongoose(options) {
|
||||
[saveSubdocs, { deduplicate: true }],
|
||||
[validateBeforeSave, { deduplicate: true }],
|
||||
[shardingPlugin, { deduplicate: true }],
|
||||
[removeSubdocs, { deduplicate: true }]
|
||||
[removeSubdocs, { deduplicate: true }],
|
||||
[trackTransaction, { deduplicate: true }]
|
||||
]
|
||||
});
|
||||
}
|
||||
@@ -121,8 +128,8 @@ Mongoose.prototype.cast = cast;
|
||||
Mongoose.prototype.STATES = STATES;
|
||||
|
||||
/**
|
||||
* The underlying driver this Mongoose instance uses to communicate with
|
||||
* the database. A driver is a Mongoose-specific interface that defines functions
|
||||
* Object with `get()` and `set()` containing the underlying driver this Mongoose instance
|
||||
* uses to communicate with the database. A driver is a Mongoose-specific interface that defines functions
|
||||
* like `find()`.
|
||||
*
|
||||
* @memberOf Mongoose
|
||||
@@ -130,7 +137,7 @@ Mongoose.prototype.STATES = STATES;
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Mongoose.prototype.driver = require('./driver');
|
||||
Mongoose.prototype.driver = driver;
|
||||
|
||||
/**
|
||||
* Sets mongoose options
|
||||
@@ -145,6 +152,7 @@ Mongoose.prototype.driver = require('./driver');
|
||||
*
|
||||
* Currently supported options are:
|
||||
* - 'debug': If `true`, prints the operations mongoose sends to MongoDB to the console. If a writable stream is passed, it will log to that stream, without colorization. If a callback function is passed, it will receive the collection name, the method name, then all arugments passed to the method. For example, if you wanted to replicate the default logging, you could output from the callback `Mongoose: ${collectionName}.${methodName}(${methodArgs.join(', ')})`.
|
||||
* - 'returnOriginal': If `false`, changes the default `returnOriginal` option to `findOneAndUpdate()`, `findByIdAndUpdate`, and `findOneAndReplace()` to false. This is equivalent to setting the `new` option to `true` for `findOneAndX()` calls by default. Read our [`findOneAndUpdate()` tutorial](/docs/tutorials/findoneandupdate.html) for more information.
|
||||
* - 'bufferCommands': enable/disable mongoose's buffering mechanism for all connections and models
|
||||
* - 'useCreateIndex': false by default. Set to `true` to make Mongoose's default index build use `createIndex()` instead of `ensureIndex()` to avoid deprecation warnings from the MongoDB driver.
|
||||
* - 'useFindAndModify': true by default. Set to `false` to make `findOneAndUpdate()` and `findOneAndRemove()` use native `findOneAndUpdate()` rather than `findAndModify()`.
|
||||
@@ -158,10 +166,13 @@ Mongoose.prototype.driver = require('./driver');
|
||||
* - 'toObject': `{ transform: true, flattenDecimals: true }` by default. Overwrites default objects to [`toObject()`](/docs/api.html#document_Document-toObject)
|
||||
* - 'toJSON': `{ transform: true, flattenDecimals: true }` by default. Overwrites default objects to [`toJSON()`](/docs/api.html#document_Document-toJSON), for determining how Mongoose documents get serialized by `JSON.stringify()`
|
||||
* - 'strict': true by default, may be `false`, `true`, or `'throw'`. Sets the default strict mode for schemas.
|
||||
* - 'strictQuery': false by default, may be `false`, `true`, or `'throw'`. Sets the default [strictQuery](/docs/guide.html#strictQuery) mode for schemas.
|
||||
* - 'selectPopulatedPaths': true by default. Set to false to opt out of Mongoose adding all fields that you `populate()` to your `select()`. The schema-level option `selectPopulatedPaths` overwrites this one.
|
||||
* - 'typePojoToMixed': true by default, may be `false` or `true`. Sets the default typePojoToMixed for schemas.
|
||||
* - 'maxTimeMS': If set, attaches [maxTimeMS](https://docs.mongodb.com/manual/reference/operator/meta/maxTimeMS/) to every query
|
||||
* - 'autoIndex': true by default. Set to false to disable automatic index creation for all models associated with this Mongoose instance.
|
||||
* - 'autoCreate': Set to `true` to make Mongoose call [`Model.createCollection()`](/docs/api/model.html#model_Model.createCollection) automatically when you create a model with `mongoose.model()` or `conn.model()`. This is useful for testing transactions, change streams, and other features that require the collection to exist.
|
||||
* - 'overwriteModels': Set to `true` to default to overwriting models with the same name when calling `mongoose.model()`, as opposed to throwing an `OverwriteModelError`.
|
||||
*
|
||||
* @param {String} key
|
||||
* @param {String|Function|Boolean} value
|
||||
@@ -213,7 +224,7 @@ Mongoose.prototype.get = Mongoose.prototype.set;
|
||||
/**
|
||||
* Creates a Connection instance.
|
||||
*
|
||||
* Each `connection` instance maps to a single database. This method is helpful when mangaging multiple db connections.
|
||||
* Each `connection` instance maps to a single database. This method is helpful when managing multiple db connections.
|
||||
*
|
||||
*
|
||||
* _Options passed take precedence over options included in connection strings._
|
||||
@@ -224,18 +235,18 @@ Mongoose.prototype.get = Mongoose.prototype.set;
|
||||
* db = mongoose.createConnection('mongodb://user:pass@localhost:port/database');
|
||||
*
|
||||
* // and options
|
||||
* var opts = { db: { native_parser: true }}
|
||||
* const opts = { db: { native_parser: true }}
|
||||
* db = mongoose.createConnection('mongodb://user:pass@localhost:port/database', opts);
|
||||
*
|
||||
* // replica sets
|
||||
* db = mongoose.createConnection('mongodb://user:pass@localhost:port,anotherhost:port,yetanother:port/database');
|
||||
*
|
||||
* // and options
|
||||
* var opts = { replset: { strategy: 'ping', rs_name: 'testSet' }}
|
||||
* const opts = { replset: { strategy: 'ping', rs_name: 'testSet' }}
|
||||
* db = mongoose.createConnection('mongodb://user:pass@localhost:port,anotherhost:port,yetanother:port/database', opts);
|
||||
*
|
||||
* // and options
|
||||
* var opts = { server: { auto_reconnect: false }, user: 'username', pass: 'mypassword' }
|
||||
* const opts = { server: { auto_reconnect: false }, user: 'username', pass: 'mypassword' }
|
||||
* db = mongoose.createConnection('localhost', 'database', port, opts)
|
||||
*
|
||||
* // initialize now, connect later
|
||||
@@ -245,7 +256,7 @@ Mongoose.prototype.get = Mongoose.prototype.set;
|
||||
* @param {String} [uri] a mongodb:// URI
|
||||
* @param {Object} [options] passed down to the [MongoDB driver's `connect()` function](http://mongodb.github.io/node-mongodb-native/3.0/api/MongoClient.html), except for 4 mongoose-specific options explained below.
|
||||
* @param {Boolean} [options.bufferCommands=true] Mongoose specific option. Set to false to [disable buffering](http://mongoosejs.com/docs/faq.html#callback_never_executes) on all models associated with this connection.
|
||||
* @param {String} [options.dbName] The name of the database we want to use. If not provided, use database name from connection string.
|
||||
* @param {String} [options.dbName] The name of the database you want to use. If not provided, Mongoose uses the database name from connection string.
|
||||
* @param {String} [options.user] username for authentication, equivalent to `options.auth.user`. Maintained for backwards compatibility.
|
||||
* @param {String} [options.pass] password for authentication, equivalent to `options.auth.password`. Maintained for backwards compatibility.
|
||||
* @param {Boolean} [options.autoIndex=true] Mongoose-specific option. Set to false to disable automatic index creation for all models associated with this connection.
|
||||
@@ -260,7 +271,7 @@ Mongoose.prototype.get = Mongoose.prototype.set;
|
||||
* @param {Number} [options.bufferMaxEntries] This option does nothing if `useUnifiedTopology` is set. The MongoDB driver also has its own buffering mechanism that kicks in when the driver is disconnected. Set this option to 0 and set `bufferCommands` to `false` on your schemas if you want your database operations to fail immediately when the driver is not connected, as opposed to waiting for reconnection.
|
||||
* @param {Number} [options.connectTimeoutMS=30000] How long the MongoDB driver will wait before killing a socket due to inactivity _during initial connection_. Defaults to 30000. This option is passed transparently to [Node.js' `socket#setTimeout()` function](https://nodejs.org/api/net.html#net_socket_settimeout_timeout_callback).
|
||||
* @param {Number} [options.socketTimeoutMS=30000] How long the MongoDB driver will wait before killing a socket due to inactivity _after initial connection_. A socket may be inactive because of either no activity or a long-running operation. This is set to `30000` by default, you should set this to 2-3x your longest running operation if you expect some of your database operations to run longer than 20 seconds. This option is passed to [Node.js `socket#setTimeout()` function](https://nodejs.org/api/net.html#net_socket_settimeout_timeout_callback) after the MongoDB driver successfully completes.
|
||||
* @param {Number} [options.family=0] Passed transparently to [Node.js' `dns.lookup()`](https://nodejs.org/api/dns.html#dns_dns_lookup_hostname_options_callback) function. May be either `0, `4`, or `6`. `4` means use IPv4 only, `6` means use IPv6 only, `0` means try both.
|
||||
* @param {Number} [options.family=0] Passed transparently to [Node.js' `dns.lookup()`](https://nodejs.org/api/dns.html#dns_dns_lookup_hostname_options_callback) function. May be either `0`, `4`, or `6`. `4` means use IPv4 only, `6` means use IPv6 only, `0` means try both.
|
||||
* @return {Connection} the created Connection object. Connections are thenable, so you can do `await mongoose.createConnection()`
|
||||
* @api public
|
||||
*/
|
||||
@@ -274,6 +285,7 @@ Mongoose.prototype.createConnection = function(uri, options, callback) {
|
||||
options = null;
|
||||
}
|
||||
_mongoose.connections.push(conn);
|
||||
_mongoose.events.emit('createConnection', conn);
|
||||
|
||||
if (arguments.length > 0) {
|
||||
return conn.openUri(uri, options, callback);
|
||||
@@ -290,14 +302,14 @@ Mongoose.prototype.createConnection = function(uri, options, callback) {
|
||||
* mongoose.connect('mongodb://user:pass@localhost:port/database');
|
||||
*
|
||||
* // replica sets
|
||||
* var uri = 'mongodb://user:pass@localhost:port,anotherhost:port,yetanother:port/mydatabase';
|
||||
* const uri = 'mongodb://user:pass@localhost:port,anotherhost:port,yetanother:port/mydatabase';
|
||||
* mongoose.connect(uri);
|
||||
*
|
||||
* // with options
|
||||
* mongoose.connect(uri, options);
|
||||
*
|
||||
* // optional callback that gets fired when initial connection completed
|
||||
* var uri = 'mongodb://nonexistent.domain:27000';
|
||||
* const uri = 'mongodb://nonexistent.domain:27000';
|
||||
* mongoose.connect(uri, function(error) {
|
||||
* // if error is truthy, the initial connection failed.
|
||||
* })
|
||||
@@ -305,6 +317,7 @@ Mongoose.prototype.createConnection = function(uri, options, callback) {
|
||||
* @param {String} uri(s)
|
||||
* @param {Object} [options] passed down to the [MongoDB driver's `connect()` function](http://mongodb.github.io/node-mongodb-native/3.0/api/MongoClient.html), except for 4 mongoose-specific options explained below.
|
||||
* @param {Boolean} [options.bufferCommands=true] Mongoose specific option. Set to false to [disable buffering](http://mongoosejs.com/docs/faq.html#callback_never_executes) on all models associated with this connection.
|
||||
* @param {Number} [options.bufferTimeoutMS=10000] Mongoose specific option. If `bufferCommands` is true, Mongoose will throw an error after `bufferTimeoutMS` if the operation is still buffered.
|
||||
* @param {String} [options.dbName] The name of the database we want to use. If not provided, use database name from connection string.
|
||||
* @param {String} [options.user] username for authentication, equivalent to `options.auth.user`. Maintained for backwards compatibility.
|
||||
* @param {String} [options.pass] password for authentication, equivalent to `options.auth.password`. Maintained for backwards compatibility.
|
||||
@@ -322,7 +335,8 @@ Mongoose.prototype.createConnection = function(uri, options, callback) {
|
||||
* @param {Number} [options.bufferMaxEntries] This option does nothing if `useUnifiedTopology` is set. The MongoDB driver also has its own buffering mechanism that kicks in when the driver is disconnected. Set this option to 0 and set `bufferCommands` to `false` on your schemas if you want your database operations to fail immediately when the driver is not connected, as opposed to waiting for reconnection.
|
||||
* @param {Number} [options.connectTimeoutMS=30000] How long the MongoDB driver will wait before killing a socket due to inactivity _during initial connection_. Defaults to 30000. This option is passed transparently to [Node.js' `socket#setTimeout()` function](https://nodejs.org/api/net.html#net_socket_settimeout_timeout_callback).
|
||||
* @param {Number} [options.socketTimeoutMS=30000] How long the MongoDB driver will wait before killing a socket due to inactivity _after initial connection_. A socket may be inactive because of either no activity or a long-running operation. This is set to `30000` by default, you should set this to 2-3x your longest running operation if you expect some of your database operations to run longer than 20 seconds. This option is passed to [Node.js `socket#setTimeout()` function](https://nodejs.org/api/net.html#net_socket_settimeout_timeout_callback) after the MongoDB driver successfully completes.
|
||||
* @param {Number} [options.family=0] Passed transparently to [Node.js' `dns.lookup()`](https://nodejs.org/api/dns.html#dns_dns_lookup_hostname_options_callback) function. May be either `0, `4`, or `6`. `4` means use IPv4 only, `6` means use IPv6 only, `0` means try both.
|
||||
* @param {Number} [options.family=0] Passed transparently to [Node.js' `dns.lookup()`](https://nodejs.org/api/dns.html#dns_dns_lookup_hostname_options_callback) function. May be either `0`, `4`, or `6`. `4` means use IPv4 only, `6` means use IPv6 only, `0` means try both.
|
||||
* @param {Boolean} [options.autoCreate=false] Set to `true` to make Mongoose automatically call `createCollection()` on every model created on this connection.
|
||||
* @param {Function} [callback]
|
||||
* @see Mongoose#createConnection #index_Mongoose-createConnection
|
||||
* @api public
|
||||
@@ -332,7 +346,15 @@ Mongoose.prototype.createConnection = function(uri, options, callback) {
|
||||
Mongoose.prototype.connect = function(uri, options, callback) {
|
||||
const _mongoose = this instanceof Mongoose ? this : mongoose;
|
||||
const conn = _mongoose.connection;
|
||||
return conn.openUri(uri, options, callback).then(() => _mongoose);
|
||||
|
||||
return _mongoose._promiseOrCallback(callback, cb => {
|
||||
conn.openUri(uri, options, err => {
|
||||
if (err != null) {
|
||||
return cb(err);
|
||||
}
|
||||
return cb(null, _mongoose);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -346,7 +368,7 @@ Mongoose.prototype.connect = function(uri, options, callback) {
|
||||
Mongoose.prototype.disconnect = function(callback) {
|
||||
const _mongoose = this instanceof Mongoose ? this : mongoose;
|
||||
|
||||
return promiseOrCallback(callback, cb => {
|
||||
return _mongoose._promiseOrCallback(callback, cb => {
|
||||
let remaining = _mongoose.connections.length;
|
||||
if (remaining <= 0) {
|
||||
return cb(null);
|
||||
@@ -415,17 +437,17 @@ Mongoose.prototype.pluralize = function(fn) {
|
||||
*
|
||||
* ####Example:
|
||||
*
|
||||
* var mongoose = require('mongoose');
|
||||
* const mongoose = require('mongoose');
|
||||
*
|
||||
* // define an Actor model with this mongoose instance
|
||||
* const schema = new Schema({ name: String });
|
||||
* mongoose.model('Actor', schema);
|
||||
*
|
||||
* // create a new connection
|
||||
* var conn = mongoose.createConnection(..);
|
||||
* const conn = mongoose.createConnection(..);
|
||||
*
|
||||
* // create Actor model
|
||||
* var Actor = conn.model('Actor', schema);
|
||||
* const Actor = conn.model('Actor', schema);
|
||||
* conn.model('Actor') === Actor; // true
|
||||
* conn.model('Actor', schema) === Actor; // true, same schema
|
||||
* conn.model('Actor', schema, 'actors') === Actor; // true, same schema and collection name
|
||||
@@ -437,7 +459,7 @@ Mongoose.prototype.pluralize = function(fn) {
|
||||
*
|
||||
* ####Example:
|
||||
*
|
||||
* var schema = new Schema({ name: String }, { collection: 'actor' });
|
||||
* const schema = new Schema({ name: String }, { collection: 'actor' });
|
||||
*
|
||||
* // or
|
||||
*
|
||||
@@ -445,13 +467,13 @@ Mongoose.prototype.pluralize = function(fn) {
|
||||
*
|
||||
* // or
|
||||
*
|
||||
* var collectionName = 'actor'
|
||||
* var M = mongoose.model('Actor', schema, collectionName)
|
||||
* const collectionName = 'actor'
|
||||
* const M = mongoose.model('Actor', schema, collectionName)
|
||||
*
|
||||
* @param {String|Function} name model name or class extending Model
|
||||
* @param {Schema} [schema] the schema to use.
|
||||
* @param {String} [collection] name (optional, inferred from model name)
|
||||
* @param {Boolean} [skipInit] whether to skip initialization (defaults to false)
|
||||
* @param {Boolean|Object} [skipInit] whether to skip initialization (defaults to false). If an object, treated as options.
|
||||
* @return {Model} The model associated with `name`. Mongoose will create the model if it doesn't already exist.
|
||||
* @api public
|
||||
*/
|
||||
@@ -473,10 +495,10 @@ Mongoose.prototype.model = function(name, schema, collection, skipInit) {
|
||||
schema = false;
|
||||
}
|
||||
|
||||
if (utils.isObject(schema) && !(schema.instanceOfSchema)) {
|
||||
if (utils.isObject(schema) && !(schema instanceof Schema)) {
|
||||
schema = new Schema(schema);
|
||||
}
|
||||
if (schema && !schema.instanceOfSchema) {
|
||||
if (schema && !(schema instanceof Schema)) {
|
||||
throw new Error('The 2nd parameter to `mongoose.model()` should be a ' +
|
||||
'schema or a POJO');
|
||||
}
|
||||
@@ -517,7 +539,10 @@ Mongoose.prototype.model = function(name, schema, collection, skipInit) {
|
||||
|
||||
// connection.model() may be passing a different schema for
|
||||
// an existing model name. in this case don't read from cache.
|
||||
if (_mongoose.models[name] && options.cache !== false) {
|
||||
const overwriteModels = _mongoose.options.hasOwnProperty('overwriteModels') ?
|
||||
_mongoose.options.overwriteModels :
|
||||
options.overwriteModels;
|
||||
if (_mongoose.models[name] && options.cache !== false && overwriteModels !== true) {
|
||||
if (originalSchema &&
|
||||
originalSchema.instanceOfSchema &&
|
||||
originalSchema !== _mongoose.models[name].schema) {
|
||||
@@ -562,6 +587,8 @@ Mongoose.prototype.model = function(name, schema, collection, skipInit) {
|
||||
model.init(function $modelInitNoop() {});
|
||||
}
|
||||
|
||||
connection.emit('model', model);
|
||||
|
||||
if (options.cache === false) {
|
||||
return model;
|
||||
}
|
||||
@@ -661,7 +688,7 @@ Mongoose.prototype.plugin = function(fn, opts) {
|
||||
*
|
||||
* ####Example:
|
||||
*
|
||||
* var mongoose = require('mongoose');
|
||||
* const mongoose = require('mongoose');
|
||||
* mongoose.connect(...);
|
||||
* mongoose.connection.on('error', cb);
|
||||
*
|
||||
@@ -709,23 +736,17 @@ Mongoose.prototype.__defineSetter__('connection', function(v) {
|
||||
|
||||
Mongoose.prototype.connections;
|
||||
|
||||
/*!
|
||||
* Driver dependent APIs
|
||||
*/
|
||||
|
||||
const driver = global.MONGOOSE_DRIVER_PATH || './drivers/node-mongodb-native';
|
||||
|
||||
/*!
|
||||
* Connection
|
||||
*/
|
||||
|
||||
const Connection = require(driver + '/connection');
|
||||
const Connection = driver.get().getConnection();
|
||||
|
||||
/*!
|
||||
* Collection
|
||||
*/
|
||||
|
||||
const Collection = require(driver + '/collection');
|
||||
const Collection = driver.get().Collection;
|
||||
|
||||
/**
|
||||
* The Mongoose Aggregate constructor
|
||||
@@ -776,8 +797,8 @@ Mongoose.prototype.version = pkg.version;
|
||||
*
|
||||
* ####Example:
|
||||
*
|
||||
* var mongoose = require('mongoose');
|
||||
* var mongoose2 = new mongoose.Mongoose();
|
||||
* const mongoose = require('mongoose');
|
||||
* const mongoose2 = new mongoose.Mongoose();
|
||||
*
|
||||
* @method Mongoose
|
||||
* @api public
|
||||
@@ -790,9 +811,9 @@ Mongoose.prototype.Mongoose = Mongoose;
|
||||
*
|
||||
* ####Example:
|
||||
*
|
||||
* var mongoose = require('mongoose');
|
||||
* var Schema = mongoose.Schema;
|
||||
* var CatSchema = new Schema(..);
|
||||
* const mongoose = require('mongoose');
|
||||
* const Schema = mongoose.Schema;
|
||||
* const CatSchema = new Schema(..);
|
||||
*
|
||||
* @method Schema
|
||||
* @api public
|
||||
@@ -837,21 +858,24 @@ Mongoose.prototype.VirtualType = VirtualType;
|
||||
*
|
||||
* ####Example:
|
||||
*
|
||||
* var mongoose = require('mongoose');
|
||||
* var array = mongoose.Types.Array;
|
||||
* const mongoose = require('mongoose');
|
||||
* const array = mongoose.Types.Array;
|
||||
*
|
||||
* ####Types:
|
||||
*
|
||||
* - [ObjectId](#types-objectid-js)
|
||||
* - [Buffer](#types-buffer-js)
|
||||
* - [SubDocument](#types-embedded-js)
|
||||
* - [Array](#types-array-js)
|
||||
* - [DocumentArray](#types-documentarray-js)
|
||||
* - [Array](/docs/schematypes.html#arrays)
|
||||
* - [Buffer](/docs/schematypes.html#buffers)
|
||||
* - [Embedded](/docs/schematypes.html#schemas)
|
||||
* - [DocumentArray](/docs/api/documentarraypath.html)
|
||||
* - [Decimal128](/docs/api.html#mongoose_Mongoose-Decimal128)
|
||||
* - [ObjectId](/docs/schematypes.html#objectids)
|
||||
* - [Map](/docs/schematypes.html#maps)
|
||||
* - [Subdocument](/docs/schematypes.html#schemas)
|
||||
*
|
||||
* Using this exposed access to the `ObjectId` type, we can construct ids on demand.
|
||||
*
|
||||
* var ObjectId = mongoose.Types.ObjectId;
|
||||
* var id1 = new ObjectId;
|
||||
* const ObjectId = mongoose.Types.ObjectId;
|
||||
* const id1 = new ObjectId;
|
||||
*
|
||||
* @property Types
|
||||
* @api public
|
||||
@@ -970,7 +994,13 @@ Mongoose.prototype.isValidObjectId = function(v) {
|
||||
}
|
||||
if (v._id.toString instanceof Function) {
|
||||
v = v._id.toString();
|
||||
return typeof v === 'string' && (v.length === 12 || v.length === 24);
|
||||
if (typeof v === 'string' && v.length === 12) {
|
||||
return true;
|
||||
}
|
||||
if (typeof v === 'string' && v.length === 24 && /^[a-f0-9]*$/.test(v)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -978,7 +1008,10 @@ Mongoose.prototype.isValidObjectId = function(v) {
|
||||
v = v.toString();
|
||||
}
|
||||
|
||||
if (typeof v === 'string' && (v.length === 12 || v.length === 24)) {
|
||||
if (typeof v === 'string' && v.length === 12) {
|
||||
return true;
|
||||
}
|
||||
if (typeof v === 'string' && v.length === 24 && /^[a-f0-9]*$/.test(v)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1108,6 +1141,14 @@ Mongoose.prototype.mongo = require('mongodb');
|
||||
|
||||
Mongoose.prototype.mquery = require('mquery');
|
||||
|
||||
/*!
|
||||
* ignore
|
||||
*/
|
||||
|
||||
Mongoose.prototype._promiseOrCallback = function(callback, fn, ee) {
|
||||
return promiseOrCallback(callback, fn, ee, this.Promise);
|
||||
};
|
||||
|
||||
/*!
|
||||
* The exports object is an instance of Mongoose.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user