Presentation is loading. Please wait.

Presentation is loading. Please wait.

Document database … one kind of NoSQL database

Similar presentations


Presentation on theme: "Document database … one kind of NoSQL database"— Presentation transcript:

1 Document database … one kind of NoSQL database
Store data that are documents, typically with some structure. Similar documents are stored in collections. Database consists of collections where each collection contains documents. Popular language for describing data is JSON e.g. { '_id' : 1, 'name' : { 'first' : 'John', 'last' : 'Backus' }, 'contribs' : [ 'Fortran', 'ALGOL', 'Backus-Naur Form', 'FP' ], 'awards' : [ 'award' : 'W.W. McDowell Award', 'year' : 1967, 'by' : 'IEEE Computer Society' }, { 'award' : 'Draper Prize', 'year' : 1993, 'by' : 'National Academy of Engineering' } ]

2 Each document has a unique object identifier
{ '_id' : 1, 'name' : { 'first' : 'John', 'last' : 'Backus' }, 'contribs' : [ 'Fortran', 'ALGOL', 'Backus-Naur Form', 'FP' ], 'awards' : [ 'award' : 'W.W. McDowell Award', 'year' : 1967, 'by' : 'IEEE Computer Society' }, { 'award' : 'Draper Prize', 'year' : 1993, 'by' : 'National Academy of Engineering' } ] Each document has a unique object identifier Name is composite Contribs is multi-valued – an array Awards is multi-valued Each award is composite

3 employee: { '_id' : , ‘Fname' : 'John', ‘Lname ‘: ‘Smith’, ‘Minit ‘: ‘B’ ‘Bdate’ : ‘ ’, … etc Dependents:[ ‘dependent_name’: ‘Michael’, ‘sex’:’M’, ‘Bdate’: ’, ‘Relationship’: ‘Son },{ ‘dependent_name’: ‘Alice’, ‘sex’:’F’, ‘Bdate’: ’, ‘Relationship’: ‘Daughter’ ‘dependent_name’: ‘Elizabeth’, ‘Relationship’: ‘Spouse’} ] } Easy to model employees and dependents in one collection as there is a natural hierarchy (the one-to-many relationship)

4 How does one handle the supervises relationship…
employee: { '_id' : , ‘Fname' : ’James', ‘Lname ‘: ‘Borg’, ‘Minit ‘: ‘E’ ‘Bdate’ : ‘ ’, … etc Dependents:[ … } ] Supervises:[ '_id' : , ‘Fname' : ‘Franklin', ‘Lname ‘: ‘Wong’, ‘Minit ‘: ‘T’ ‘Bdate’ : ‘ ’, } How does one handle the supervises relationship… Could embed each employee within their supervisor Notice that each employee will have a Supervises entry

5 How does one handle the supervises relationship…
Or, each employee is a separate document with references to other employees via the object identifier Don’t expect to be able to specify a join operation … rather need to program this Employee: { '_id' : , ‘Fname' : James', ‘Lname ‘: ‘Borg’, ‘Minit ‘: ‘E’ ‘Bdate’ : ‘ ’, … etc Dependents:[ … } ] Supervises [ ObjectID(‘ ’), ObjectID(‘ ’), … employee:[ '_id' : , ‘Fname' : ‘Franklin', ‘Lname ‘: ‘Wong’, ‘Minit ‘: ‘T’ ‘Bdate’ : ‘ ’, Supervises: [ObjectID:(‘ ’)] } To get the employees supervised by e = db.employees.find ( { _id: } ) Subordinates = db.employees.find ( { _id: $in e.Supervises} )


Download ppt "Document database … one kind of NoSQL database"

Similar presentations


Ads by Google