~hanspayer/+junk/mongocourse

« back to all changes in this revision

Viewing changes to chapter2/examples/setter_example.js

  • Committer: Payer Hans-Christian
  • Date: 2016-02-03 14:28:09 UTC
  • Revision ID: hans@net-so.org-20160203142809-p8fwwzi52uxriozs
ausgang fuer HW 2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
var mongoose = require('mongoose');
 
2
var productSchema = require('./product');
 
3
 
 
4
var Product = mongoose.model('Product', productSchema);
 
5
 
 
6
var p = new Product({
 
7
  name: 'test',
 
8
  price: {
 
9
    amount: 5,
 
10
    currency: 'USD'
 
11
  },
 
12
  category: {
 
13
    name: 'test'
 
14
  }
 
15
});
 
16
 
 
17
console.log(p.internal.approximatePriceUSD); // 5
 
18
 
 
19
p.price.amount = 88;
 
20
console.log(p.internal.approximatePriceUSD); // 88
 
21
 
 
22
p.price.currency = 'EUR';
 
23
console.log(p.internal.approximatePriceUSD); // 80
 
24
p.price.amount = 11;
 
25
console.log(p.internal.approximatePriceUSD); // 10