0

When I log the object right before saving it, it looks like this:

{
    "type": "events",
    "labels": [
        "abc",
        "123"
    ],
    "keywords": [
        [
            "a",
            "b",
            "c",
            "d",
            "e"
        ],
        [
            "1",
            "2",
            "3",
            "4",
            "5"
        ]
    ],
    "_id": "4d9ddac669cb3bf5e855a366"
}

but then if i go into the mongo shell it saves like this...

{
    "_id": ObjectId("4d9ddac669cb3bf5e855a366"),
    "keywords": [

    ],
    "labels": [
        "abc",
        "123"
    ],
    "type": "events"
}

any ideas?

1 Answer 1

1

Saving that directly in the MongoDB shell keeps the nesting structure:

{
    "_id" : "4d9ddac669cb3bf5e855a366",
    "type" : "events",
    "labels" : [
        "abc",
        "123"
    ],
    "keywords" : [
        [
            "a",
            "b",
            "c",
            "d",
            "e"
        ],
        [
            "1",
            "2",
            "3",
            "4",
            "5"
        ]
    ]
}

And as far as I know all the official drivers handle the nested arrays correctly. It sounds like the BSON writer in Node may be skipping the outer array.

Can you run a few similar tests saving the same thing in the shell and with Node and see if they differ?

Sign up to request clarification or add additional context in comments.

1 Comment

Inserting via the shell it works fine. I'm using Mongoose on top of Mongo within Node.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.