diff --git a/lib/types/array.js b/lib/types/array.js index f80201d887f..c9b831c11cd 100644 --- a/lib/types/array.js +++ b/lib/types/array.js @@ -193,9 +193,10 @@ MongooseArray.prototype.$pushAll = function (value) { * @api public */ +MongooseArray.prototype.pop = MongooseArray.prototype.$pop = function () { this._registerAtomic('$pop', 1); - return this.pop(); + return [].pop.call(this) }; /** @@ -208,9 +209,10 @@ MongooseArray.prototype.$pop = function () { * @api public */ -MongooseArray.prototype.$shift = function () { +MongooseArray.prototype.shift = +MongooseArray.prototype.$shift = function $shift () { this._registerAtomic('$pop', -1); - return this.shift(); + return [].shift.call(this) }; /** @@ -323,6 +325,7 @@ MongooseArray.prototype.splice = function () { * @api public */ +MongooseArray.prototype.$unshift = MongooseArray.prototype.unshift = function () { var values = [].map.call(arguments, this._cast, this); [].unshift.apply(this, values); @@ -331,6 +334,7 @@ MongooseArray.prototype.unshift = function () { }; /** +MongooseArray.prototype.$shift = * Adds values to the array if not already present. * @api public */ diff --git a/test/types.array.test.js b/test/types.array.test.js index 2fdad23baa3..3e70511248d 100644 --- a/test/types.array.test.js +++ b/test/types.array.test.js @@ -63,6 +63,38 @@ module.exports = { }, + '$push is push': function() { + var db = start() + var User = db.model('User') + var tj = new User({ name: 'tj', pets: []}) + tj.pets.push.should.equal(tj.pets.$push) + db.close() + }, + + '$pop is pop': function() { + var db = start() + var User = db.model('User') + var tj = new User({ name: 'tj', pets: []}) + tj.pets.pop.should.equal(tj.pets.$pop) + db.close() + }, + + '$shift is shift': function() { + var db = start() + var User = db.model('User') + var tj = new User({ name: 'tj', pets: []}) + tj.pets.shift.should.equal(tj.pets.$shift) + db.close() + }, + + '$unshift is unshift': function() { + var db = start() + var User = db.model('User') + var tj = new User({ name: 'tj', pets: []}) + tj.pets.unshift.should.equal(tj.pets.$unshift) + db.close() + }, + 'test indexOf()': function(){ var db = start() , User = db.model('User', 'users_' + random())