diff --git a/History.md b/History.md index f569b18a1b..480b112b93 100644 --- a/History.md +++ b/History.md @@ -3,7 +3,7 @@ * Fail explicitly when publishing non-cursors. * Implement `$each`, `$sort`, and `$slice` options for minimongo's `$push` - modifier. + modifier. #1492 * Increase the maximum size spiderable will return for a page from 200kB to 5MB. @@ -11,6 +11,8 @@ * Upgraded dependencies: * SockJS server from 0.3.7 to 0.3.8 +Patches contributed by GitHub user mcbain. + ## v0.6.6.1 diff --git a/packages/mongo-livedata/mongo_livedata_tests.js b/packages/mongo-livedata/mongo_livedata_tests.js index 33877d6218..9e3cd712b1 100644 --- a/packages/mongo-livedata/mongo_livedata_tests.js +++ b/packages/mongo-livedata/mongo_livedata_tests.js @@ -1815,3 +1815,55 @@ Tinytest.addAsync("mongo-livedata - local collection with null connection, w/o c test.equal(coll1.findOne(doc)._id, docId); onComplete(); }); + +Tinytest.add("mongo-livedata - update handles $push with $each correctly", function (test) { + var collection = new Meteor.Collection(Random.id()); + + var id = collection.insert({name: 'jens', elements: ['X', 'Y']}); + + var result = collection.update(id, { + $push: { + elements: { + $each: ['A', 'B', 'C'], + $slice: -4 + }}}); + + test.equal(collection.findOne(id), { + _id: id, + name: 'jens', + elements: ['Y', 'A', 'B', 'C'] + }); +}); + +if (Meteor.isServer) { + Tinytest.add("mongo-livedata - upsert handles $push with $each correctly", function (test) { + var collection = new Meteor.Collection(Random.id()); + + var result = collection.upsert( + {name: 'jens'}, + {$push: { + elements: { + $each: ['A', 'B', 'C'], + $slice: -4 + }}}); + + test.equal(collection.findOne(result.insertedId), + {_id: result.insertedId, + name: 'jens', + elements: ['A', 'B', 'C']}); + + var id = collection.insert({name: "david", elements: ['X', 'Y']}); + result = collection.upsert( + {name: 'david'}, + {$push: { + elements: { + $each: ['A', 'B', 'C'], + $slice: -4 + }}}); + + test.equal(collection.findOne(id), + {_id: id, + name: 'david', + elements: ['Y', 'A', 'B', 'C']}); + }); +}