node.js - 使用空子文档(数组)在猫鼬中插入文档,创建空文档?
问题描述
const mongoose = require('mongoose');
const orgSchema = new mongoose.Schema({
org_name : {
type : String,
required : true
},
admin : {
type : String,
required : true
},
branches : [{
branch_name : {
type : String,
required :true
},
branch_admin : {
type : String,
required : true
},
branch_locations : [{
_id : false,
sub_branch_name : {
type : String
},
sub_branch_admin : {
type : String
}
}]
}],
plan : {
type : mongoose.Schema.Types.ObjectId,
ref : 'plan',
required : true
},
status : {
type : String,
enum : ['ACTIVE', 'EXPIRED']
}
});
orgSchema.createIndex = ({
org_name : 1
},{
unique : true
});
module.exports = mongoose.model('organizations', orgSchema);
//上面是架构
{
"_id" : ObjectId("5bf91a1edc7ed22ca90d4624"),
"org_name" : "xxxxxxxxxxxxxxx",
"admin" : "sssssss",
"branches" : [
{
"_id" : ObjectId("5bf91a1edc7ed22ca90d4625"),
"branch_name" : "ssssss",
"branch_admin" : "ddd",
"branch_locations" : [
{}//automatically creates empty doc when no fields
]
}
],
"plan" : ObjectId("5bf91a1edc7ed22ca90d4623"),
"status" : "ACTIVE",
"__v" : 0
当我尝试在子文档数组中插入一个包含空字段的文档时,它会在子文档数组中返回 {}。如何摆脱子文档中的新空文档。当子文档中没有要保存的字段时,我应该得到一个空数组...
解决方案
推荐阅读
- php - 在 wordpress 页面/帖子仪表板中显示特色图片
- java - 基于条件的 Java 子字符串
- docker - 如何使用 docker:dind 图像运行单个命令(任务)容器
- python - 如何有效地识别 numpy 数组中的“类似 HSV-to-neightbours”像素?
- complexity-theory - 具有更简单决策版本的非平凡问题
- java - openGL ES 旋转 AR 对象
- html - 在 Bootstrap 中均匀分布嵌套的行/列?
- php - CSS由于某种原因没有加载
- python - 比较python中不同文件扩展名(pdf和word)的表数据
- flutter - 颤振错误:未为类“对象”定义运算符“[]”?