trerums
trerums

Reputation: 397

MongoDB schemaless design - advantage or mess?

I've been developing EAV(entity-attribute-value)web application.

The main reason i want use mongo is it's schemaless, i.e it's very easy to find a car with "color" attribute without having unnecessary fields.

Here is the short example of document structure to be implemented:

Ware from Computers category:

    {
     name: "Core i7",
     category: 1,
     properties:{
       price:300,
       vendor: "Intel",
       ...
     }
    }

Meanwhile there is ware from Automobile category with it's own set of attributes:

    {
     name: "Audi Q7",
     category: 2,
     properties:{
       price:30000,
       color:"red",
       hp:200
       ...
     }

}

But if i have 100 categories my db will store 100 different documents(by it's structure). MongoDB docs says that's documents can be schemaless, but it's good practice to have less or more same structure of documents.

My question is: is it very bad practice to have a lot of different structure documents?

Upvotes: 0

Views: 915

Answers (2)

Derick
Derick

Reputation: 36774

I would say that for things like your "product" catalog, it's perfectly reasonable to have a different structure per document. Actually, you don't have a different top level structure at all, it's just that the properties for each of your items has different elements in the array.

Upvotes: 1

Sergio Tulentsev
Sergio Tulentsev

Reputation: 230296

"Good" or "bad" is very subjective. If it brings more benefits than harm, then it's good. Otherwise, it's probably not.

Since MongoDB is schemaless, here you, at least, can have tons of documents with different structure (as opposed to relational DBs). This fact by itself is neutral. It's your usage of it that'll make it good or bad for your application.

Upvotes: 4

Related Questions