Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 把手:已拒绝访问以解决该物业的问题”;名称“;因为它不是一个;“自有财产”;母公司的_Node.js_Mongodb_Mongoose_Handlebars.js_Express Handlebars - Fatal编程技术网

Node.js 把手:已拒绝访问以解决该物业的问题”;名称“;因为它不是一个;“自有财产”;母公司的

Node.js 把手:已拒绝访问以解决该物业的问题”;名称“;因为它不是一个;“自有财产”;母公司的,node.js,mongodb,mongoose,handlebars.js,express-handlebars,Node.js,Mongodb,Mongoose,Handlebars.js,Express Handlebars,车把4.7.3有问题。我已经检查了这个问题的解决方案, 但这并不是我的代码的解决方案,所以我希望有人能帮助我 Controller.js submitPosts: (req, res) => { // Check the attributs from create.handlebars for success or error message const newPost = new Post( { surname: req.body.

车把4.7.3有问题。我已经检查了这个问题的解决方案, 但这并不是我的代码的解决方案,所以我希望有人能帮助我

Controller.js

submitPosts: (req, res) => {
        // Check the attributs from create.handlebars for success or error message
        const newPost = new Post( {
            surname: req.body.surname,
            name: req.body.name,
            biography: req.body.biography,
            profilpicture: req.body.profilpicture,
            paintings: req.body.paintings,
        });
        // Safe new posts
        newPost.save().then(post => {
            console.log(post);
            flash('success-message', 'new post!')
            res.redirect('/admin/posts');
        });

    },
postModel.js

const
    mongoose = require('mongoose');

const Schema = mongoose.Schema; // get props

const PostSchema = new Schema({
    // define props --> required for a post

    surname: {
        type: String,
        default: ''
    },
    name: {
        type: String,
        default: ''
    },
    biography: {
        type: String,
        default: ''
    },
    profilpicture: {
        type: Object,
    },
    paintings : {
        type: Object,
    }


});

module.exports = mongoose.model('post', PostSchema);
索引把手

{{#each post}}
            <tr>
                <td>{{ surname }}</td>
                <td>{{ name }}</td>
                <td><img style="width: 100px; height:100px;" src="{{ profilpicture }}"></td>
                <td>{{ biography }}</td>
                <td><img style="width: 100px; height:100px;" src="{{ paintings }}"></td>
            </tr>
            {{/each}}
{{#每篇文章}
{{姓氏}
{{name}}
{{传记}
{{/每个}}

已经尝试了从其他堆栈溢出,其他手柄版本,更改路由器代码等各种可能性。。。什么都不管用:(

就是有同样的问题,伤了我的神经。 尝试了其他包等,但最后一个简单的命令解决了这个问题。 这是命令“.lean()” 可在此处找到更多信息:

我的代码示例:

// show message page Route
router.get("/", (req, res) => {
//read all Message entries from db
   Message.find() 
   //sort them descending by date property
   .sort({ date: "desc" })
   .lean()
   //take these and call the rendered page and pass them as object to the page
   .then(messages => {
     res.render("messages/show_messages", { messages: messages });
   });
});

@Dariun是的,在您的路由中使用此选项。我的示例在路由器文件中使用。因此,如果您没有使用单独的路由器文件,请在“app.get…”路由中使用“.lean()”函数。不要复制我的路由。在路由中插入“.lean()”