These are chat archives for Automattic/mongoose

5th
Jun 2017
Дмитрий
@CatBegemot
Jun 05 2017 14:11
who can help me?
app.post('/folder/:id/add', function (req, res) {
    var folderChild = new Folder();
    folderChild.name = req.body.nameFolder;
    // Folder.findById(req.params.id, (err, folder) => {
    //         folderChild.parent = folder;
    //         console.log("this place");
    //         console.log('Child', folderChild);
    //         console.log('----------');
    //         console.log('Parent', folder);
    // });
    Folder.findById(req.params.id, function (err, folder) {
         folderChild.parent = folder;
         console.log(folderChild);
         folderChild.save((err) => {
             if (err) {
                 console.log(err);
                 return;
             }
             else {
                 console.log('Child', folderChild);
                 res.redirect('/root');
             }
         });
     });
    // folderChild.parent = req.params.id;
});
Aaron Bell
@awb715
Jun 05 2017 15:04
@CatBegemot what r u trying to do
Дмитрий
@CatBegemot
Jun 05 2017 17:05
i want create folder > subfolder. I using mongoose-path-tree
@awb715 my model
let mongoose = require('mongoose');
let tree = require('mongoose-tree');

// Folder Schema
let folderSchema = new mongoose.Schema({
    name: {
        type: String,
        required: true
    }
});

folderSchema.plugin(tree);

let Folder = module.exports = mongoose.model('Folder', folderSchema);
but folderChild.save() not working
who can help me?