TypeError:elements.find不是NodeJS +猫鼬的函数

时间:2018-11-02 16:52:00

标签: javascript node.js mongoose

我正在尝试这段代码,但收到以下错误:“ TypeError:elements.find不是函数”

你能帮我吗?

这是我的模特

const mongoose = require('mongoose');

const elementSchema = new mongoose.Schema({
    nombre: {
        type: String,
        required: true
    },
    comunidad: {
        type: String,
        required: true
    },
    fabricante: {
        type: String,
        required: true
    },
    fecharegistro: {
        type: Date,
        defaault: Date.now
    }

});

module.exports = mongoose.model('Element', elementSchema);

我把它放在我的routes.js中:

const elements = require('./models/elements')();

app.get('/network-elements', isLoggedIn, (req, res) => {
        elements.find({}, (err, element) =>{
            if (err) throw err;
            res.render('network-elements', {
                user: req.user,
                nombre: elements.nombre
            });
        });

    });

然后当我尝试查看networ-elements.ejs时收到错误消息

1 个答案:

答案 0 :(得分:0)

您的导入就是关于这一点:

public class myClass implements Tasklet, InitializingBean {

    private String ratesFilePath;
    private File ratesFile = new File(ratesFilePath);

    public String getRatesFilePath() {
        return ratesFilePath;
    }

    public void setRatesFilePath(String ratesFilePath) {
        this.ratesFilePath = ratesFilePath;
    }
}

实际上,在模块导入中确实需要此“()”!