Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var taskSchema = new Schema({
- name: String,
- completed: Boolean,
- subtasks: [{name: String, completed: Boolean}],
- description: String
- });
- var listSchema = new Schema({
- name: String,
- author: String,
- tasks: [
- {
- type: Schema.Types.ObjectId,
- ref: 'Task'
- }
- ]
- });
- //this is how I'm trying to push a newly created task into the list
- List.findById(req.body.listId, function(err, list) {
- var newTask = new Task({
- name: req.body.newTaskName,
- completed: false
- })
- newTask.save(function (err, task) {
- if (err) {
- console.log(err);
- return res.sendStatus(500);
- };
- list.tasks.push(task._id);
- return res.json({
- _id: task._id
- });
- });
- });
- //this is how I'm trying to populate tasks in the list
- List.find({
- author: req.user.username
- }).populate('tasks').exec(function (err, data) {
- //some stuff
- return res.json(result);
- });
- nothing is being added to list.tasks, mongodb shell is showing an empty array
Advertisement
Add Comment
Please, Sign In to add comment