1 | var connection = require(__dirname + '/../dadi/lib/model/connection')
|
2 | var config = require(__dirname + '/../config').database
|
3 |
|
4 | config.database = 'testdb'
|
5 |
|
6 | var conn = connection(config)
|
7 |
|
8 | conn.on('connect', function (db) {
|
9 |
|
10 | db.collection('user').insert({
|
11 | name: 'Tolstoy'
|
12 | }, function (err, doc) {
|
13 | if (err) throw err
|
14 |
|
15 | console.log(db)
|
16 |
|
17 | db.collection('books').insert({
|
18 | name: 'War and Peace',
|
19 | authorId: doc[0]._id
|
20 | }, function (err, books) {
|
21 | if (err) throw err
|
22 |
|
23 | console.log('Send a GET request to the following URL in Postman to see joined collection:')
|
24 | console.log('\thttp://localhost:3000/v1/full-book?bookid=' + books[0]._id)
|
25 | conn.mongoClient.close()
|
26 | })
|
27 | })
|
28 | })
|