mongoose数据类型问题
发布于 10 年前 作者 39092207 4897 次浏览 最后一次编辑是 8 年前 来自 问答

在mongoose中如果某一个字段的类型未知,或者希望将来给他赋值一个对象(任何对象),这个该怎么定义,如下 var optLogSchema = new Schema({ target: {//操作对象(任意对象,没有固定的结构)
type:????? } }); module.exports = optLogSchema;

5 回复
var optLogSchema = new Schema({
    target: {}
});
var optLogSchema = new Schema({
  target: {type: Object}
});

这样可以么 感觉好像行啊

@kenticny 没见过这么写的啊

@39092207 可以的,正式环境用过

createPreson       : String,
created            : {type : Date, default : Date.now},

可以啊。

回到顶部