mongodb - 收到一条错误消息,指出 MongoDB 中的嵌套架构

标签 mongodb express

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

const userSchema = new Schema({
    name: String,
    created: new Date()
})

const user = mongoose.model('user', userSchema);

module.exports = user;

添加 new Date() 后,我收到一条错误消息: 类型错误:创建时未定义类型未定义 您尝试过嵌套架构吗?您只能使用引用或数组进行嵌套。

最佳答案

您正在定义模式,您只需要一个类型而不是对象。不使用 new Date(),只需使用 Date

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

const userSchema = new Schema({
    name: String,
    created: Date
})

const user = mongoose.model('user', userSchema);

module.exports = user;

关于mongodb - 收到一条错误消息,指出 MongoDB 中的嵌套架构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52639186/

相关文章:

node.js - 在 Node js 应用程序中全局共享 mongodb 连接对象

mongodb烛台查询

mongodb - 如果我们使用分片,mongodb 中的唯一索引

Mongodb Base64 图像与 gridfs

node.js - 运行 grunt watch 时 - 它在运行 Express 服务器任务时抛出警告并中止

javascript - mongodb 从一个值中获取整个文档

debugging - 如何调试导致 100% cpu 使用的 node.js?

node.js - Express 4 session 类型错误 : object is not a function

javascript - 访问node.js中xhr请求发送的数据

node.js - Express/Jade 中的 "include template"是什么?