关系数据库和nosql设计schema时的差别的例子
在关系数据库中和nosql的设计时,对于schema的设计是不同的.比如MYSQL中,设计如下一个例子:
mysql> select * from people;+----+------------+| id | name |+----+------------+| 1 | Stephane || 2 | John || 3 | Michael || 4 | Cinderella |+----+------------+mysql> select * from passports;+----+-----------+---------+-------------+| id | people_id | country | valid_until |+----+-----------+---------+-------------+| 4 | 1 | FR | 2020-01-01 || 5 | 2 | US | 2020-01-01 || 6 | 3 | RU | 2020-01-01 |+----+-----------+---------+-------------+
> db.people_all.find().pretty(){"_id" : ObjectId("51f7be1cd6189a56c399d3bf"),"name" : "Stephane","country" : "FR","valid_until" : ISODate("2019-12-31T23:00:00Z")}{"_id" : ObjectId("51f7be3fd6189a56c399d3c0"),"name" : "John","country" : "US","valid_until" : ISODate("2019-12-31T23:00:00Z")}{"_id" : ObjectId("51f7be4dd6189a56c399d3c1"),"name" : "Michael","country" : "RU","valid_until" : ISODate("2019-12-31T23:00:00Z")}{ "_id" : ObjectId("51f7be5cd6189a56c399d3c2"), "name" : "Cinderella" }
> db.people_embed.find().pretty(){"_id" : ObjectId("51f7c0048ded44d5ebb83774"),"name" : "Stephane","passport" : {"country" : "FR","valid_until" : ISODate("2019-12-31T23:00:00Z")}}{"_id" : ObjectId("51f7c70e8ded44d5ebb83775"),"name" : "John","passport" : {"country" : "US","valid_until" : ISODate("2019-12-31T23:00:00Z")}}{"_id" : ObjectId("51f7c71b8ded44d5ebb83776"),"name" : "Michael","passport" : {"country" : "RU","valid_until" : ISODate("2019-12-31T23:00:00Z")}}{ "_id" : ObjectId("51f7c7258ded44d5ebb83777"), "name" : "Cinderella" }
> db.passports_embed.find().pretty(){"_id" : ObjectId("51f7c7e58ded44d5ebb8377b"),"country" : "FR","valid_until" : ISODate("2019-12-31T23:00:00Z"),"person" : {"name" : "Stephane"}}{"_id" : ObjectId("51f7c7ec8ded44d5ebb8377c"),"country" : "US","valid_until" : ISODate("2019-12-31T23:00:00Z"),"person" : {"name" : "John"}}{"_id" : ObjectId("51f7c7fa8ded44d5ebb8377d"),"country" : "RU","valid_until" : ISODate("2019-12-31T23:00:00Z"),"person" : {"name" : "Michael"}}{"_id" : ObjectId("51f7c8058ded44d5ebb8377e"),"person" : {"name" : "Cinderella"}}