简体   繁体   English

这个模型怎么了

[英]what's wrong with this model

I need to develop a module for getting data from mongodb, I already have other models working in my application, but this one does not, this is my schemas: 我需要开发一个用于从mongodb获取数据的模块,我的应用程序中已经有其他模型在工作,但是这个不是,这是我的模式:

var mongoose = require('mongoose');
var ProvinciaSchema = new mongoose.Schema({
"nome":String,
"tc_provincia_id":Number,
"id" : Number,
"codice_regione" : Number,
"codice" : Number,
"sigla" : Number
},{collection:'province'})
module.exports = ProvinciaSchema;

this is my model: 这是我的模型:

var mongoose = require('mongoose');
var ProvinciaSchema = require('../schemas/provincia');
var Provincia = mongoose.model('provincia', ProvinciaSchema);
module.exports = Provincia;

This is how I use the model: 这就是我使用模型的方式:

var Provincia = require('../../models/provincia');
Provincia.find({},next( err, province){
if (err){console.log('errorre whoosh '+err);
     return next(err,province)
     }
     if (!province){console.log('trovato nulla')}
     console.log('callback tc_istat_id')
     return next(err,province)
 })

where 哪里

next =function(err,prov){
    t.equivalent(out,expect)
    t.end()

when I launch the test if the condition argument is correct, the execution stuck at Provincia.find and the callback function it is not executed, if I put a wrong condition the section of the code of if(err) is executed, I think there is a problem with my schemas abnd models, but I do not understand what. 如果条件参数正确,则启动测试时,执行将停留在Provincia.find上,并且不会执行该回调函数,如果我输入了错误的条件,则会执行if(err)的代码段,我的架构和模型有问题,但是我不明白。

 function myFunction(callback) {
       Provincia.find({},next( err, province){
            if (err) {
                console.log('errorre whoosh '+err);
                return next(err,province)
             }
            if (!province){
                console.log('trovato nulla');
                return false;
            }
            console.log('callback tc_istat_id')


            callback(err,province)
       })
 }

 myFunction(function(err,prov){
     t.equivalent(out,expect)
     t.end()
 });

I had no way of testing this but it is how I would set up my callback function. 我没有测试的方法,但是这是设置回调函数的方式。 Let me know what you log, and what errors your get if this does not work 让我知道您记录了什么,如果不起作用会得到什么错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM