Mongodb 如何使用mongoose返回完整对象
我想知道是否有一种方法可以检索完整的文档(即使使用未定义的和空的键) 这是我的模式:Mongodb 如何使用mongoose返回完整对象,mongodb,mongoose,Mongodb,Mongoose,我想知道是否有一种方法可以检索完整的文档(即使使用未定义的和空的键) 这是我的模式: var userSchema = new Schema({ username : {type: String, index: {unique: true, dropDups: true}} , password : String , email : {type: String, index: {unique: true, dropDups: true}} ,
var userSchema = new Schema({
username : {type: String, index: {unique: true, dropDups: true}} ,
password : String ,
email : {type: String, index: {unique: true, dropDups: true}} ,
gender : String
})
假设某个用户的性别没有定义,当我查询时,我只得到用户名、密码和电子邮件。。我怎么也能知道性别
抱歉,如果有任何错误的技术术语。关键是在类型定义中使用
default
属性来提供默认值
var userSchema = new Schema({
username : {type: String, index: {unique: true, dropDups: true}} ,
password : String ,
email : {type: String, index: {unique: true, dropDups: true}} ,
gender : {type: String, default: "Unknown" }
})
有关更多信息,文档为。如果没有性别,为什么会有性别?我想检索整个文档,以便将其作为json发送到我的模板。。如果性别不存在,则会导致错误。。我不想在前端处理这个问题。我知道这不是mongodb的工作方式。但这就是我的目的!