I need just a bit of advice.

I am working with node.js and React and mongoDb

I just want that please take a look at my schema architecture (Specially for address) for profile and suggest me which is better

Approach 1 :
The things that scared me with this approach. I tried this also But it become unnecessary headaches to insert address and then query address as it is nested schema .
Also if you check this out
[Answer by Konstantin Smolyanin (Long Version))]
One must not considered nested state in react.

Approach 2
I can store address into another collection

Also is there any reference sites where I can learn about schema architecture or database design with practical scenarios.

Thanks for reading out.

  • 0
    I don't see your headaches with approach 1... Unless there's a possibility for not a one to one relation between users and addresses, I'd personally go with the first approach.
  • 0
    @100110111 hmm with First approach I face issue when adding/updating address

    Something like this

    handleChange = async ({ currentTarget: input }) => {

    data[input.name] = input.value;


    But as it is nested Now I need to do

    handleAddrChange = async ({ currentTarget: input }) => {

    data['addresss'][input.name] = input.value;


    I mean for nested I need to write two functions :( Not seems good to me
  • 1
    I haven't really worked with NoSQL databases yet, but I still think that thr basic rules of database normalization apply here. So addresses should definitely be a new "table" (or whatever you call that in NoSQL dbs)
  • 0
    Sort of. They're optimized for different workloads.

    Each record is a document, as opposed to a tuple of fixed positional column values. The documents can also have variable schema in the same collection. Many times, a document will be an aggregate, and feature both internal object and arrays.

    Lastly, there's no cross-collection relationships, so most of Codd's forms don't really slot in. Mongo also really only supports left outer join, so the referential possibilities are limited.
Add Comment