Vivek Kumar
Vivek Kumar

Reputation: 5040

Is it possible to create a collection in mongodb as key-value

I am very new to mongodb. Due to lack of time to study mongodb in depth, I'm asking this question.

Is it possible to create a collection in key-value pattern without using _id.

"1", "2", "3" will act as a key instead of _id.

{
    "1": {
        "name": "X",
        "address": {
            "street": "abc",
            "zip": 12345
        }
    },
    "2": {
        "name": "Y",
        "address": {
            "street": "efg",
            "zip": 12346
        }
    },
    "3": {
        "name": "Z",
        "address": {
            "street": "lmn",
            "zip": 12347
        }
    }
}

EDIT 1: Can I say Mongodb's collection is a array?

Upvotes: 1

Views: 73

Answers (1)

Vivek Kumar
Vivek Kumar

Reputation: 5040

After my finding, It seems that Mongodb's collection is a array of documents. So, this is not possible as what I've mentioned in my question.

But I can do something like

{ "_id" : "12345", "3" : { "name" : "krishna" } }
{ "_id" : "123" }

Upvotes: 1

Related Questions