Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixed; addToSet with Dates works

  • Loading branch information...
commit 35c5e993363b0464abf04c223f8bdfb4c5e53724 1 parent 3b66d9b
@aheckmann aheckmann authored
Showing with 16 additions and 4 deletions.
  1. +16 −4 lib/types/array.js
View
20 lib/types/array.js
@@ -328,12 +328,24 @@ MongooseArray.prototype.unshift = function () {
MongooseArray.prototype.$addToSet =
MongooseArray.prototype.addToSet = function addToSet () {
var values = Array.prototype.map.call(arguments, this._cast, this)
- , added = [];
+ , added = []
+ , type = values[0] instanceof EmbeddedDocument ? 'doc' :
+ values[0] instanceof Date ? 'date' :
+ '';
values.forEach(function (v) {
- var found = v instanceof EmbeddedDocument
- ? this.some(function(doc){ return doc.equals(v) })
- : ~this.indexOf(v)
+ var found;
+ switch (type) {
+ case 'doc':
+ found = this.some(function(doc){ return doc.equals(v) });
+ break;
+ case 'date':
+ var val = +v;
+ found = this.some(function(d){ return +d === val });
+ break;
+ default:
+ found = ~this.indexOf(v);
+ }
if (!found) {
oldPush.call(this, v);
Please sign in to comment.
Something went wrong with that request. Please try again.