forked from hungvietdo/MSCHackathon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconnect.js
More file actions
39 lines (29 loc) · 1010 Bytes
/
connect.js
File metadata and controls
39 lines (29 loc) · 1010 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
var assert = require('assert')
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var ObjectId = mongoose.Types.ObjectId;
console.log('\n===========');
console.log(' mongoose version: %s', mongoose.version);
console.log('========\n\n');
var dbname = 'test';
console.log('dbname: %s', dbname);
mongoose.connect('http://ec2-54-201-34-143.us-west-2.compute.amazonaws.com', dbname);
mongoose.connection.on('error', function () {
console.error('connection error', arguments);
});
var user = new Schema({
name: String
, friends: [{ type: Schema.ObjectId, ref: 'User' }]
});
var User = mongoose.model('User', user);
var blogpost = Schema({
title: String
, tags: [String]
, author: { type: Schema.ObjectId, ref: 'User' }
})
var BlogPost = mongoose.model('BlogPost', blogpost);
mongoose.connection.on('open', function () {
BlogPost.find({ tags: 'fun' }).lean().populate('author').exec(function (err, docs) {
console.log(docs);
})
});