mblarsen / mongoose-hidden

A Mongoose schema plugin for filtering properties you usually do not want to sent client-side like passwords and IDs.
MIT License
89 stars 19 forks source link

Nested document arrays are no longer arrays after toJSON/toObject #30

Closed lavarsicious closed 7 years ago

lavarsicious commented 7 years ago

Hello,

As of v1.1.0 I've noticed that nested document arrays are no longer returned as actual arrays. I've created pull request https://github.com/mblarsen/mongoose-hidden/pull/29 that adds a test for this scenario.

The test, "A test for a document with a collection of nested documents" passes in versions prior to 1.1.0 but after https://github.com/mblarsen/mongoose-hidden/commit/bf74c77794590b1550ec43ba7736a833f42374d4 it seems that arrays are now returned as objects with indexes as keys.

Version 1.0.0:

    {
        "name": "Joe",
        "email": "joe@example.com",
        "companies": [
            {
                "name": "GOGGLE",
                "code": "GOG"
            },
            {
                "name": "APPLE",
                "code": "APL"
            }
        ]
    }

Version 1.1.0:

    {
        "name": "Joe",
        "email": "joe@example.com",
        "companies": {
            "0": {
                "name": "GOGGLE",
                "code": "GOG"
            }
        }
    }

Thanks!

mblarsen commented 7 years ago

Hi @lavarsicious I'll look into it tomorrow. Thanks a lot for the test case.

mblarsen commented 7 years ago

@lavarsicious did you ever get to try new version?

lavarsicious commented 7 years ago

@mblarsen Yes! 1.2.0 is working as expected, thank you.