【问题标题】:foo.find(...).execFind is not a function - mongoose schema modelfoo.find(...).execFind 不是函数 - 猫鼬模式模型
【发布时间】:2016-04-22 18:29:04
【问题描述】:

我已经定义了一个自定义类型,我正在尝试从包含在引用集合中的 mongo 返回所有条目:

参与者.js

var mongoose = require('mongoose');
var Schema = mongoose.Schema;

var participantSchema= new Schema({
    email: String,
});

module.exports =  mongoose.model('Participant', participantSchema, 'participants')

api.js

var express = require('express');
var router = express.Router();
var mongoose = require('mongoose');
var Participant = require('../models/Participant');

router.get('/all', function(req, res) {
    var participant = mongoose.model('Participant');
    //var participant = new Participant();
    console.log(participant);
    participant.find().execFind(function (arr,data) {
        res.send(data);
    });
});

module.exports = router;

但由于某些问题,我的模型没有扩展(我假设默认原型)

 participant.find(...).execFind is not a function

TypeError: participant.find(...).execFind is not a function
    at /Users/bogdan/private/appName/routes/api.js:13:24

非常感谢任何帮助... 谢谢

【问题讨论】:

  • 尝试调用exec 而不是execFind
  • 谢谢,添加评论,也许你能解释一下有什么区别:p
  • execFind 在 3.x 版本之一中被删除,不确定何时。反正已经被exec取代了。
  • add answere s oi 可以接受 :)

标签: node.js mongodb mongoose schema


【解决方案1】:

execFind 在 Mongoose 的 3.x 版本之一中被替换为 exec

所以你现在必须调用exec 而不是execFind

【讨论】:

    猜你喜欢
    • 2023-01-28
    • 1970-01-01
    • 1970-01-01
    • 2012-01-14
    • 1970-01-01
    • 2020-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多