在猫鼬中,方法save();不工作

时间:2019-08-09 16:53:04

标签: node.js mongodb typescript mongoose

当我尝试使用猫鼬在mongo中保存任何内容时,方法save()的回调;返回我好吧,这意味着所有内容都保存在MongoDB中,但是当我在控制台中检查MongoDB时,没有任何保存只是DB空了。值得注意的是,我在docker容器上使用了mongo。

Conecction.ts

At line 556 of file ../../topslave.F
Fortran runtime error: Pointer actual argument 'buffer2' is not associated

Client.ts

import  mongoose from 'mongoose';

const DB_URL:string = 'mongodb://localhost:27017';

mongoose.connect(DB_URL,{
    useNewUrlParser: true,
    user:'admin',
    pass:'qwerty12345',
    dbName:'veterinaria_db'
});


export default mongoose.connection

Controller.ts

import  mongoose from 'mongoose';
const Schema:any = mongoose.Schema;
import db from '../db/Conecction';


db.on('error',console.error.bind(console, 'connection error:'));
db.once('open',()=>{
    console.log('DB: Connected Susesfuly!!');
});

export interface IClient extends mongoose.Document{
    name:string,
    first_last_name:string,
    second_last_name:string,
    username:string,
    password:string,
    mail:string,
    phone:string,
    cellphone:string,
    history:[{
        appoinments:{
            pets:{
                name:string,
                type:string,
                age:number
            },
            date:Date,
            reason:string,
            status:number
        }
    }]
};

export const ClientSchema = Schema({
    name:String,
    first_last_name:String,
    second_last_name:String,
    username:String,
    password:String,
    mail:String,
    phone:String,
    cellphone:String,
    history:[{
        appoinments:{
            pets:{
                name:String,
                type:String,
                age:Number
            },
            date:Date,
            reason:String,
            status:Number
        }
    }]
});


export default db.model<IClient>('Client',ClientSchema);

1 个答案:

答案 0 :(得分:0)

我不确定帖子的第一行是否有问题。

让{名称,名字,名字,用户名,密码,邮件,电话,手机,历史记录} =请求正文;

如果以json的形式提供,请保留并执行以下操作: let newClient = new Client(req.body);

当console.log错误和!error登录时,将记录什么?