Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixed; empty arrays are now saved

  • Loading branch information...
commit 6bcf771b772a87bef04d9d5d99deeaf47dc0f0df 1 parent 3c9c535
@aheckmann aheckmann authored
Showing with 2 additions and 6 deletions.
  1. +1 −5 lib/mongoose/utils.js
  2. +1 −1  test/document.test.js
6 lib/mongoose/utils.js
@@ -150,11 +150,7 @@ exports.EventEmitter = Events;
var clone = exports.clone = function (obj, shouldMinimizeData) {
if (obj === undefined || obj === null)
return obj
- if (Array.isArray(obj)) {
- return (obj.length || !shouldMinimizeData)
- ? cloneArray(obj, shouldMinimizeData)
- : undefined;
- }
+ if (Array.isArray(obj)) return cloneArray(obj, shouldMinimizeData);
if (obj.toObject)
return obj.toObject();
if (obj.constructor == Object) {
2  test/document.test.js
@@ -460,7 +460,7 @@ module.exports = {
, obj = doc.toObject();
delete obj._id;
- obj.should.eql({});
+ obj.should.eql({ oids: [] });

4 comments on commit 6bcf771


Aaron, just seeing this commit. What do you think of the following idea? As an alternative to persisting empty arrays, we could choose not to persist them (i.e., oids isn't saved in the test above). In this scenario, we could write mongoose so that it hydrates any undefined Array types as empty arrays. This could save storage overhead for keys that the app developer intends to use sparsely but still behave in the same way the app developer expects mongoose to behave. I'd probably prefer this approach. Thoughts?


Regardless, the clone utility should clone, not just clone according to mongoose/mongodb logic.


So we'll have clone and miniMe functions? Done.


Brian, sounds good.

Please sign in to comment.
Something went wrong with that request. Please try again.