UNPKG

781 BJavaScriptView Raw
1var connection = require(__dirname + '/../dadi/lib/model/connection')
2var config = require(__dirname + '/../config').database
3
4config.database = 'testdb'
5
6var conn = connection(config)
7
8conn.on('connect', function (db) {
9 // Note: this is for QA testing or example purposes only
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})