1

In SQL I usually would have tables/entities Account and AccountDetails, Address etc.

Account { Id, Name, Password }
AccountDetails { AccountId, LastSignedIn, CreatedDate, /*etc*/}
Address {AccountDetailsId, City, Country, /*etc*/ }

In NoSQL type of database should I store all that in one?

Account { Id, Name, Password, LastSignedIn, CreatedDate, City, Country, /*etc*/}

Another words: should I normalize NoSQL documents?

Can u please advice?

In my particular case I am using mongodb with mongoose.

Community
  • 1
  • 1
Sergino
  • 10,128
  • 30
  • 98
  • 159

1 Answers1

1

NoSQL is a too general term, it depends on the particular database you consider. But it is true that in some of them (and also depending on the particular case) it is better not to normalize.

For instance in MongoDB is usually preferred to use arrays and subdocuments than normalizing. If you normalize then you need to join, and joins are not one of the strengths of Mongo.

RafaelCaballero
  • 1,555
  • 2
  • 17
  • 24
  • just updated the question. I am using `mongodb` with `mongoose` – Sergino Feb 13 '16 at 01:41
  • Then, as I said in many cases it is better to have just one big collections. Of course there are exceptions, it depends on the cardinality of the relationship (integrating two tables representing a many-to-many relationship can lead to a combinatorial explosion....) – RafaelCaballero Feb 13 '16 at 01:44
  • So if I have `document` and its `subdocuments` can I say to retrieve the particular `subdocument` or skip the other one with `findqueries`? Something like: `Account.findOne({name:'user'}, include: {'subdoc1'})` - so it will include whatever the the `subdoc1` is and wont include any other `subdocuments` in result – Sergino Feb 13 '16 at 01:50
  • Yes, for instance with a document like {name:'xx', telfs:{cell:'56565',house:'12121'}} you can write `db.people.find({name:'xx'},{'telfs.home':1})` with the notation telfs.home:1 indicating "inside key telfs look for key home and if it exists display its value" – RafaelCaballero Feb 13 '16 at 01:58
  • just created separate question for this http://stackoverflow.com/questions/35375243/how-to-skip-and-include-subdocuments-with-mongoose-quiery – Sergino Feb 13 '16 at 02:04
  • good idea, more people can give their opinion. Good luck! – RafaelCaballero Feb 13 '16 at 02:08