javascript - $push 创建一个只有 _id 的新对象,没有属性——feathsjs+mongoose
问题描述
我正在尝试使用 $push 将对象(具有一个属性,文本)插入到子文档的数组中:
await this.app.service("someService").patch(
null,
{
$push: { "subDocuments.$.textArray": { text: "stuff" }}
},
{
query: {
_id: parentId,
"subDocuments._id": subDocumentId
}
}
);
}
该模型如下所示:
const ParentSchema = new Schema({
subDocuments: [SubDocumentSchema]
});
const SubDocumentSchema = new Schema({
textArray: [
{
text: { type: String }
}
]
});
该对象已创建,但它是一个以 _id 作为其唯一属性的空对象。我错过了什么?
解决方案
请声明架构,如:
const ParentSchema = new Schema({
subDocuments: [SubDocumentSchema]
});
const SubDocumentSchema = new Schema({
textArray: [
{
text: { type: String }
}
]
}, { _id: false });
推荐阅读
- android-studio - Android Studio 调试器在到达断点后崩溃
- java - 如何通过 SSL 从开发机器连接到 Heroku shield Postgres 数据库
- azure - 使用 SignalR 的 Azure 应用服务访问限制
- snmp - 如何使用 snmp 修复未定义的标识符错误
- vue.js - Vue awesome swiper 在 vue js modal 插件中无法正常工作
- python-3.x - 如何抑制“类型没有预期的属性”
- javascript - 即使指定了宽度和高度,溢出 x 也不起作用
- json - JsounUtils.fromJson - 第一个字母是大写字母,JsonUtils 不会用大写字母映射字段
- xampp - Xampp 启动 SQL 而不是意外关闭。似乎没有解决方案有效
- arrays - 从大型未排序对象创建对象数组