node.js - Mongo Atlas 中没有创建集合
问题描述
This is my .js file that contains the routes .
var express = require("express");
var bcrypt = require("bcryptjs");
var router = express.Router();
var passport = require("passport");
//User model
var User = require("../models/StudentUser.js");
router.post("/studentRegister",(req,res) =>
{
const {username,password,phone_no,student_id,dob,school,batch}=req.body;
let errors = [];
if(!student_id|| !username || !password || !phone_no || !dob || !school || !batch ){
errors.push({msg:"Please fill in all fields."});
}
if(errors.length>0)
{
res.render("../views/signupStudent.ejs",{
errors,
username,
password,
phone_no,
student_id,
dob,
school,
batch
});
}
else{
var newUser = new User({
username,
password,
phone_no,
student_id,
dob,
school,
batch
});
newUser.save(function(err)
{
if(err){
console.log(err);
}
else
{
res.redirect("../views/dashboard.ejs");
console.log("success");
}
});
}
});
module.exports = router;
以下是我创建的架构:
var mongoose = require("mongoose");
var passportLocalMongoose= require("passport-local-mongoose");
var StudentUserSchema = new mongoose.Schema({
username:{
type: String,
required: true
},
password:{
type: String,
required: true
},
student_id:{
type:String,
required:true
},
phone_no:{
type: String,
required: true
},
dob:{
type: Date,
default: Date.now
},
school:{
type: String,
required: true
},
batch:{
type: String,
required: true
}
});
StudentUserSchema.plugin(passportLocalMongoose);
module.exports = User = mongoose.model("User",StudentUserSchema);
我在文件中使用了 console.log(newUser) 来检查新用户详细信息是否已更新,但没有显示任何内容。我的 Atlas Cluster 中也没有创建任何集合。MongoDB 连接已确认,但没有进一步的进展。错误处理也不起作用,也不会引发错误。
请暂时忽略我的代码的错误处理方面。我主要关心的是确保正在创建与我的集群中的模式相对应的集合(在确认连接时我已正确包含的关键 api)。谢谢你!
解决方案
推荐阅读
- android - 如何在 Flutter 上使用 cookie 发出 http 请求?
- typescript - Angular 中的条件验证
- r - R DataExplorer 包 - 无法使用函数
- php - 一行中的 get() + sum() laravel
- javascript - 取消导航时的Vue-router回调
- apache-spark - Spark - 简单线性回归
- python - python中的函数不返回分配给变量的最新字符串值
- c++ - 需要帮助编写 for 循环以在字符串周围创建边框
- r - 合并R中的两个数据框并附加一列
- python - 处理从文件读取的文件名中的反斜杠转义