mongoose 3.6.16 → 3.6.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/History.md +51 -0
- package/README.md +1 -1
- package/lib/document.js +15 -4
- package/lib/index.js +26 -1
- package/lib/model.js +25 -1
- package/lib/query.js +15 -4
- package/lib/schema/embedded.js +41 -0
- package/package.json +3 -3
package/History.md
CHANGED
|
@@ -1,4 +1,41 @@
|
|
|
1
1
|
|
|
2
|
+
3.6.20 (stable) / 2013-09-23
|
|
3
|
+
===================
|
|
4
|
+
|
|
5
|
+
* fixed; repopulating modified populated paths #1697
|
|
6
|
+
* fixed; doc.equals w/ _id false #1687
|
|
7
|
+
* fixed; strict mode warning #1686
|
|
8
|
+
* docs; near/nearSphere
|
|
9
|
+
|
|
10
|
+
3.6.19 (stable) / 2013-09-04
|
|
11
|
+
==================
|
|
12
|
+
|
|
13
|
+
* fixed; population field selection w/ strings #1669
|
|
14
|
+
* docs; Date method caveats #1598
|
|
15
|
+
|
|
16
|
+
3.6.18 (stable) / 2013-08-22
|
|
17
|
+
===================
|
|
18
|
+
|
|
19
|
+
* updated; warn when using an unstable version of mongoose
|
|
20
|
+
* updated; mocha to 1.12.0
|
|
21
|
+
* updated; mongodb driver to 1.3.19 (fix error swallowing behavior)
|
|
22
|
+
* fixed; setters not firing on null values #1445 [ebensing](https://github.com/ebensing)
|
|
23
|
+
* fixed; properly exclude subdocument fields #1280 [ebensing](https://github.com/ebensing)
|
|
24
|
+
* fixed; cast error in findAndModify #1643 [aheuermann](https://github.com/aheuermann)
|
|
25
|
+
* website; update guide
|
|
26
|
+
* website; added documentation for safe:false and versioning interaction
|
|
27
|
+
* docs; mention that middleware dont run on Models
|
|
28
|
+
* docs; fix indexes link
|
|
29
|
+
* make; suppress warning msg in test
|
|
30
|
+
* tests; moar
|
|
31
|
+
|
|
32
|
+
3.6.17 / 2013-08-13
|
|
33
|
+
===================
|
|
34
|
+
|
|
35
|
+
* updated; driver to 1.3.18 (fixes memory leak)
|
|
36
|
+
* fixed; casting ref docs on creation #1606
|
|
37
|
+
* docs; query options
|
|
38
|
+
|
|
2
39
|
3.6.16 / 2013-08-08
|
|
3
40
|
===================
|
|
4
41
|
|
|
@@ -323,6 +360,20 @@
|
|
|
323
360
|
* updated; mpath to 0.1.1
|
|
324
361
|
* updated; docs
|
|
325
362
|
|
|
363
|
+
3.5.16 / 2013-08-13
|
|
364
|
+
===================
|
|
365
|
+
|
|
366
|
+
* updated; driver to 1.3.18
|
|
367
|
+
|
|
368
|
+
3.5.15 / 2013-07-26
|
|
369
|
+
==================
|
|
370
|
+
|
|
371
|
+
* updated; sliced to 0.0.5
|
|
372
|
+
* updated; driver to 1.3.12
|
|
373
|
+
* fixed; regression in Query#count() due to driver change
|
|
374
|
+
* tests; fixed timeouts
|
|
375
|
+
* tests; handle differing test uris
|
|
376
|
+
|
|
326
377
|
3.5.14 / 2013-05-15
|
|
327
378
|
===================
|
|
328
379
|
|
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ Mongoose is a [MongoDB](http://www.mongodb.org/) object modeling tool designed t
|
|
|
14
14
|
- [Stack Overflow](http://stackoverflow.com/questions/tagged/mongoose)
|
|
15
15
|
- [bug reports](https://github.com/learnboost/mongoose/issues/)
|
|
16
16
|
- [help forum](http://groups.google.com/group/mongoose-orm)
|
|
17
|
-
- [
|
|
17
|
+
- [MongoDB support](http://www.mongodb.org/display/DOCS/Technical+Support)
|
|
18
18
|
- (irc) #mongoosejs on freenode
|
|
19
19
|
|
|
20
20
|
## Installation
|
package/lib/document.js
CHANGED
|
@@ -163,6 +163,7 @@ Document.prototype.$__buildDoc = function (obj, fields, skipId) {
|
|
|
163
163
|
, path = p.split('.')
|
|
164
164
|
, len = path.length
|
|
165
165
|
, last = len-1
|
|
166
|
+
, curPath = ''
|
|
166
167
|
, doc_ = doc
|
|
167
168
|
, i = 0
|
|
168
169
|
|
|
@@ -170,6 +171,13 @@ Document.prototype.$__buildDoc = function (obj, fields, skipId) {
|
|
|
170
171
|
var piece = path[i]
|
|
171
172
|
, def
|
|
172
173
|
|
|
174
|
+
// support excluding intermediary levels
|
|
175
|
+
if (exclude) {
|
|
176
|
+
curPath += piece;
|
|
177
|
+
if (curPath in fields) break;
|
|
178
|
+
curPath += '.';
|
|
179
|
+
}
|
|
180
|
+
|
|
173
181
|
if (i === last) {
|
|
174
182
|
if (fields) {
|
|
175
183
|
if (exclude) {
|
|
@@ -429,15 +437,18 @@ Document.prototype.set = function (path, val, type, options) {
|
|
|
429
437
|
, pathtype
|
|
430
438
|
, key
|
|
431
439
|
|
|
440
|
+
|
|
432
441
|
while (i--) {
|
|
433
442
|
key = keys[i];
|
|
434
443
|
pathtype = this.schema.pathType(prefix + key);
|
|
435
444
|
if (null != path[key]
|
|
436
|
-
// need to know if plain object - no Buffer, ObjectId, etc
|
|
445
|
+
// need to know if plain object - no Buffer, ObjectId, ref, etc
|
|
437
446
|
&& utils.isObject(path[key])
|
|
438
447
|
&& (!path[key].constructor || 'Object' == path[key].constructor.name)
|
|
439
448
|
&& 'virtual' != pathtype
|
|
440
|
-
&& !(this.$__path(prefix + key) instanceof MixedSchema)
|
|
449
|
+
&& !(this.$__path(prefix + key) instanceof MixedSchema)
|
|
450
|
+
&& !(this.schema.paths[key] && this.schema.paths[key].options.ref)
|
|
451
|
+
) {
|
|
441
452
|
this.set(path[key], prefix + key, constructing);
|
|
442
453
|
} else if (strict) {
|
|
443
454
|
if ('real' === pathtype || 'virtual' === pathtype) {
|
|
@@ -524,7 +535,7 @@ Document.prototype.set = function (path, val, type, options) {
|
|
|
524
535
|
? undefined
|
|
525
536
|
: this.get(path);
|
|
526
537
|
|
|
527
|
-
if (!schema ||
|
|
538
|
+
if (!schema || undefined === val) {
|
|
528
539
|
this.$__set(pathToMark, path, constructing, parts, schema, val, priorVal);
|
|
529
540
|
return this;
|
|
530
541
|
}
|
|
@@ -1580,7 +1591,7 @@ Document.prototype.toString = Document.prototype.inspect;
|
|
|
1580
1591
|
Document.prototype.equals = function (doc) {
|
|
1581
1592
|
var tid = this.get('_id');
|
|
1582
1593
|
var docid = doc.get('_id');
|
|
1583
|
-
return tid.equals
|
|
1594
|
+
return tid && tid.equals
|
|
1584
1595
|
? tid.equals(docid)
|
|
1585
1596
|
: tid === docid;
|
|
1586
1597
|
}
|
package/lib/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
'use strict';
|
|
1
2
|
|
|
2
3
|
/*!
|
|
3
4
|
* Module dependencies.
|
|
@@ -16,6 +17,30 @@ var Schema = require('./schema')
|
|
|
16
17
|
, utils = require('./utils')
|
|
17
18
|
, format = utils.toCollectionName
|
|
18
19
|
, mongodb = require('mongodb')
|
|
20
|
+
, pkg = require('../package.json')
|
|
21
|
+
|
|
22
|
+
/*!
|
|
23
|
+
* Warn users if they are running an unstable release.
|
|
24
|
+
*
|
|
25
|
+
* Disable the warning by setting the MONGOOSE_DISABLE_STABILITY_WARNING
|
|
26
|
+
* environment variable.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
if (pkg.publishConfig && 'unstable' == pkg.publishConfig.tag) {
|
|
30
|
+
if (!process.env.MONGOOSE_DISABLE_STABILITY_WARNING) {
|
|
31
|
+
console.log('\u001b[33m');
|
|
32
|
+
console.log('##############################################################');
|
|
33
|
+
console.log('#');
|
|
34
|
+
console.log('# !!! MONGOOSE WARNING !!!');
|
|
35
|
+
console.log('#');
|
|
36
|
+
console.log('# This is an UNSTABLE release of Mongoose.');
|
|
37
|
+
console.log('# Unstable releases are available for preview/testing only.');
|
|
38
|
+
console.log('# DO NOT run this in production.');
|
|
39
|
+
console.log('#');
|
|
40
|
+
console.log('##############################################################');
|
|
41
|
+
console.log('\u001b[0m');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
19
44
|
|
|
20
45
|
/**
|
|
21
46
|
* Mongoose constructor.
|
|
@@ -444,7 +469,7 @@ Mongoose.prototype.Connection = Connection;
|
|
|
444
469
|
* @api public
|
|
445
470
|
*/
|
|
446
471
|
|
|
447
|
-
Mongoose.prototype.version =
|
|
472
|
+
Mongoose.prototype.version = pkg.version;
|
|
448
473
|
|
|
449
474
|
/**
|
|
450
475
|
* The Mongoose constructor
|
package/lib/model.js
CHANGED
|
@@ -1812,6 +1812,8 @@ function populateDocs (docs, options, cb) {
|
|
|
1812
1812
|
}
|
|
1813
1813
|
|
|
1814
1814
|
if (ret) {
|
|
1815
|
+
ret = convertTo_id(ret);
|
|
1816
|
+
|
|
1815
1817
|
// previously we always assigned this even if the document had no _id
|
|
1816
1818
|
options._docs[id] = Array.isArray(ret)
|
|
1817
1819
|
? ret.slice()
|
|
@@ -1855,7 +1857,7 @@ function populateDocs (docs, options, cb) {
|
|
|
1855
1857
|
// for document matching during assignment. we'll delete the
|
|
1856
1858
|
// _id back off before returning the result.
|
|
1857
1859
|
if ('string' == typeof select) {
|
|
1858
|
-
select =
|
|
1860
|
+
select = select.replace(/\s?-_id\s?/g, ' ');
|
|
1859
1861
|
} else {
|
|
1860
1862
|
// preserve original select conditions by copying
|
|
1861
1863
|
select = utils.object.shallowCopy(select);
|
|
@@ -1905,6 +1907,28 @@ function populateDocs (docs, options, cb) {
|
|
|
1905
1907
|
});
|
|
1906
1908
|
}
|
|
1907
1909
|
|
|
1910
|
+
/*!
|
|
1911
|
+
* Retrieve the _id of `val` if a Document or Array of Documents.
|
|
1912
|
+
*
|
|
1913
|
+
* @param {Array|Document|Any} val
|
|
1914
|
+
* @return {Array|Document|Any}
|
|
1915
|
+
*/
|
|
1916
|
+
|
|
1917
|
+
function convertTo_id (val) {
|
|
1918
|
+
if (val instanceof Model) return val._id;
|
|
1919
|
+
|
|
1920
|
+
if (Array.isArray(val)) {
|
|
1921
|
+
for (var i = 0; i < val.length; ++i) {
|
|
1922
|
+
if (val[i] instanceof Model) {
|
|
1923
|
+
val[i] = val[i]._id;
|
|
1924
|
+
}
|
|
1925
|
+
}
|
|
1926
|
+
return val;
|
|
1927
|
+
}
|
|
1928
|
+
|
|
1929
|
+
return val;
|
|
1930
|
+
}
|
|
1931
|
+
|
|
1908
1932
|
/*!
|
|
1909
1933
|
* Assigns documents returned from a population query back
|
|
1910
1934
|
* to the original document path.
|
package/lib/query.js
CHANGED
|
@@ -51,7 +51,8 @@ function Query (criteria, options) {
|
|
|
51
51
|
* - [hint](http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%24hint) *
|
|
52
52
|
* - [slaveOk](http://docs.mongodb.org/manual/applications/replication/#read-preference) *
|
|
53
53
|
* - [lean](./api.html#query_Query-lean) *
|
|
54
|
-
*
|
|
54
|
+
*
|
|
55
|
+
* All other [options](http://mongodb.github.io/node-mongodb-native/api-generated/cursor.html#constructor) specified will be passed unaltered to the driver.
|
|
55
56
|
*
|
|
56
57
|
* _* denotes a query helper method is also available_
|
|
57
58
|
*
|
|
@@ -864,8 +865,13 @@ Query.prototype.and = function and (array) {
|
|
|
864
865
|
/**
|
|
865
866
|
* Specifies a `$near` condition
|
|
866
867
|
*
|
|
868
|
+
* query.near('loc', [10, 20])
|
|
869
|
+
* query.near([10, 20])
|
|
870
|
+
*
|
|
871
|
+
* _NOTE: does not currently support GeoJSON._
|
|
872
|
+
*
|
|
867
873
|
* @param {String} path
|
|
868
|
-
* @param {
|
|
874
|
+
* @param {Array} val
|
|
869
875
|
* @return {Query} this
|
|
870
876
|
* @see http://www.mongodb.org/display/DOCS/Geospatial+Indexing
|
|
871
877
|
* @see $near http://docs.mongodb.org/manual/reference/operator/near/
|
|
@@ -890,8 +896,13 @@ Query.prototype.near = function (path, val) {
|
|
|
890
896
|
/**
|
|
891
897
|
* Specifies a `$nearSphere` condition.
|
|
892
898
|
*
|
|
899
|
+
* query.nearSphere('loc', [10, 20])
|
|
900
|
+
* query.nearSphere([10, 20])
|
|
901
|
+
*
|
|
902
|
+
* _NOTE: does not currently support GeoJSON._
|
|
903
|
+
*
|
|
893
904
|
* @param {String} path
|
|
894
|
-
* @param {
|
|
905
|
+
* @param {Array} val
|
|
895
906
|
* @return {Query} this
|
|
896
907
|
* @see http://www.mongodb.org/display/DOCS/Geospatial+Indexing
|
|
897
908
|
* @see $nearSphere http://docs.mongodb.org/manual/reference/operator/nearSphere/
|
|
@@ -2145,7 +2156,7 @@ Query.prototype._castUpdateVal = function _castUpdateVal (schema, val, op, $cond
|
|
|
2145
2156
|
}
|
|
2146
2157
|
|
|
2147
2158
|
if (schema.caster && op in castOps &&
|
|
2148
|
-
(
|
|
2159
|
+
(utils.isObject(val) || Array.isArray(val))) {
|
|
2149
2160
|
// Cast values for ops that add data to MongoDB.
|
|
2150
2161
|
// Ensures embedded documents get ObjectIds etc.
|
|
2151
2162
|
var tmp = schema.cast(val);
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
|
|
2
|
+
/*!
|
|
3
|
+
* Module dependencies.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
var SchemaType = require('../schematype')
|
|
7
|
+
, CastError = SchemaType.CastError
|
|
8
|
+
, errorMessages = require('../error').messages
|
|
9
|
+
, utils = require('../utils')
|
|
10
|
+
, Document
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* EmbeddedDocument SchemaType constructor.
|
|
14
|
+
*
|
|
15
|
+
* @param {String} key
|
|
16
|
+
* @param {Object} options
|
|
17
|
+
* @inherits SchemaType
|
|
18
|
+
* @api private
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
function SchemaEmbedded (key, options, EmbeddedDoc, parentArray) {
|
|
22
|
+
SchemaType.call(this, key, options, 'EmbeddedDocument');
|
|
23
|
+
this.EmbeddedDoc = EmbeddedDoc;
|
|
24
|
+
this.parentArray = parentArray;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/*!
|
|
28
|
+
* Inherits from SchemaType.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
SchemaEmbedded.prototype.__proto__ = SchemaType.prototype;
|
|
32
|
+
|
|
33
|
+
SchemaEmbedded.prototype.cast = function (value, doc, init) {
|
|
34
|
+
return new this.EmbeddedDoc(value, this.parentArray);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/*!
|
|
38
|
+
* Module exports.
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
module.exports = SchemaEmbedded;
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mongoose"
|
|
3
3
|
, "description": "Elegant MongoDB object modeling for Node.js"
|
|
4
|
-
, "version": "3.6.
|
|
4
|
+
, "version": "3.6.20"
|
|
5
5
|
, "author": "Guillermo Rauch <guillermo@learnboost.com>"
|
|
6
6
|
, "keywords": ["mongodb", "document", "model", "schema", "database", "odm", "data", "datastore", "query", "nosql", "orm", "db"]
|
|
7
7
|
, "dependencies": {
|
|
8
8
|
"hooks": "0.2.1"
|
|
9
|
-
, "mongodb": "1.3.
|
|
9
|
+
, "mongodb": "1.3.19"
|
|
10
10
|
, "ms": "0.1.0"
|
|
11
11
|
, "sliced": "0.0.5"
|
|
12
12
|
, "muri": "0.3.1"
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
, "regexp-clone": "0.0.1"
|
|
16
16
|
}
|
|
17
17
|
, "devDependencies": {
|
|
18
|
-
"mocha": "1.
|
|
18
|
+
"mocha": "1.12.0"
|
|
19
19
|
, "node-static": "0.5.9"
|
|
20
20
|
, "dox": "0.3.1"
|
|
21
21
|
, "jade": "0.26.3"
|