Difference between revisions of "MongoDB Answers"

From mi-linux
Jump to navigationJump to search
Line 2: Line 2:
  
  
== Answers to Section 1 ==
+
== Answers to Section 2 ==
  
 
<p style="color: red">
 
<p style="color: red">
Line 8: Line 8:
 
</p>
 
</p>
  
Exercise 1.1
+
=== Exercise 2.1 ===
 +
 
 +
* Compare how you added the above data and how it differs from INSERT records in a relational database
 +
 
 +
Think about how this differs from using INSERT statements in Oracle to add the data.
 +
 
 +
* Try and add Department 30. Note it has some values for the comm field.
 +
 
 +
<pre style="color:blue">
 +
db.deptCollection.insert(
 +
{
 +
    deptno: 30,
 +
    dname: 'SALES',
 +
    loc: 'CHICAGO',
 +
    employees: [
 +
    {
 +
        empno: 7499,
 +
        ename: 'ALLEN',
 +
        job: 'SALESMAN',
 +
        mgr: 7698,
 +
        hiredate: new Date('1995-02-20'),
 +
        sal: 1600,
 +
        comm: 300
 +
    },
 +
    {
 +
        empno: 7698,
 +
        ename: 'BLAKE',
 +
        job: 'MANAGER',
 +
        mgr: 7839,
 +
        hiredate: new Date('1981-05-01'),
 +
        sal: 2850
 +
    },
 +
    {  empno: 7900,
 +
        ename: 'JAMES',
 +
        job: 'CLERK',
 +
        mgr: 7698,
 +
        hiredate: new Date('1981-12-03'),
 +
        sal: 1600
 +
    },
 +
    {
 +
        empno: 7654,
 +
        ename: 'MARTIN',
 +
        job: 'SALESMAN',
 +
        mgr: 7698,
 +
        hiredate: new Date('1993-09-28'),
 +
        sal: 1250,
 +
        comm: 1400
 +
    },
 +
    {  empno: 7844,
 +
        ename: 'TURNER',
 +
        job: 'SALESMAN',
 +
        mgr: 7698,
 +
        hiredate: new Date('1981-09-08'),
 +
        sal: 1500,
 +
        comm: 0
 +
    },
 +
    {
 +
        empno: 7521,
 +
        ename: 'WARD',
 +
        job: 'SALESMAN',
 +
        mgr: 7698,
 +
        hiredate: new Date('1994-02-22'),
 +
        sal: 1250,
 +
        comm: 500
 +
    } ]
 +
})
 +
</pre>

Revision as of 14:31, 24 October 2016

Main Page >> MongoDB >>MongoDB Workbook >> Exercise Answers


Answers to Section 2

You should only look at the answers once you have attempted them yourself!

Exercise 2.1

  • Compare how you added the above data and how it differs from INSERT records in a relational database

Think about how this differs from using INSERT statements in Oracle to add the data.

  • Try and add Department 30. Note it has some values for the comm field.
db.deptCollection.insert( 
 {
    deptno: 30, 
    dname: 'SALES',
    loc: 'CHICAGO',
    employees: [
    {
        empno: 7499,
        ename: 'ALLEN',	
        job: 'SALESMAN',
        mgr: 7698, 	
        hiredate: new Date('1995-02-20'),
        sal: 1600,
        comm: 300
    },
    {
        empno: 7698,
        ename: 'BLAKE',	
        job: 'MANAGER',
        mgr: 7839, 	
        hiredate: new Date('1981-05-01'),
        sal: 2850
    }, 	 	 	 	
    {   empno: 7900,
        ename: 'JAMES',	
        job: 'CLERK',
        mgr: 7698, 	
        hiredate: new Date('1981-12-03'),
        sal: 1600
    },
    {
        empno: 7654,
        ename: 'MARTIN',	
        job: 'SALESMAN',
        mgr: 7698, 	
        hiredate: new Date('1993-09-28'),
        sal: 1250,
        comm: 1400
    },
    {   empno: 7844,
        ename: 'TURNER',	
        job: 'SALESMAN',
        mgr: 7698, 	
        hiredate: new Date('1981-09-08'),
        sal: 1500,
        comm: 0
    },
    {
        empno: 7521,
        ename: 'WARD',	
        job: 'SALESMAN',
        mgr: 7698, 	
        hiredate: new Date('1994-02-22'),
        sal: 1250,
        comm: 500
    } ]
 })