-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateUserProject.js
More file actions
46 lines (33 loc) · 985 Bytes
/
createUserProject.js
File metadata and controls
46 lines (33 loc) · 985 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
40
41
42
43
44
45
var mongoose = require( 'mongoose' );
exports.create = function( req, res ) {
var User = mongoose.model('User');
var Project = mongoose.model('Project');
var admin = new User({
username: "admin",
password: "admin",
name: "User Example Test"
});
var project = new Project({
name: "Project 1 Test"
});
project.save(function (err) {
if (err) return handleError(err);
// thats it!
});
admin.projects.push(project);
admin.save(function (err) {
if (err) return handleError(err);
});
res.send('Create complete.');
};
exports.get = function( req, res ) {
var User = mongoose.model('User');
User
.findOne({ username: 'admin' })
.populate('projects') // only works if we pushed refs to children
.exec(function (err, user) {
if (err) return handleError(err);
console.log(user);
})
res.send('Get complete.');
};