用方括号括起来的Javascript成员变量
我试图调试Node.JS和Mongoose未正确保存数据的问题。我有一个包含多个嵌套对象和对象数组的大型对象。在保存之前,我正在Chrome的devtools和节点devtools中查看它。只有几个嵌套对象存在此问题。对象数组中的成员变量用方括号[]括起来。我在保存之前查看节点devtools中的数据时发现了这一点用方括号括起来的Javascript成员变量,javascript,arrays,node.js,mongodb,mongoose,Javascript,Arrays,Node.js,Mongodb,Mongoose,我试图调试Node.JS和Mongoose未正确保存数据的问题。我有一个包含多个嵌套对象和对象数组的大型对象。在保存之前,我正在Chrome的devtools和节点devtools中查看它。只有几个嵌套对象存在此问题。对象数组中的成员变量用方括号[]括起来。我在保存之前查看节点devtools中的数据时发现了这一点 0: Object [attributeName]: "Grow raccoon tail" [componentId]: "58918f2c6f92704b0868
0: Object
[attributeName]: "Grow raccoon tail"
[componentId]: "58918f2c6f92704b0868aa30"
[derivativeName]: ""
[entityId]: "58918f9d6f92704b0868aa3e"
[isStateVariable]: "false"
[name]: "Feather"
[parentId]: "0"
[startValue]: "0"
[variableName]: "tail"
这是问题对象的模式
var componentVariableSchema = mongoose.Schema({
componentId: { type: ObjectId },
entityId: { type: ObjectId },
name: String,
attributeName: String,
isStateVariable: { type: Boolean, default: false },
variableName: String,
derivativeName: String,
startValue: { type: Number, default: 0.0 }
},
{
timestamps: true
});
下面是父对象的模式
var simulationSchema = mongoose.Schema({
createdDate: { type: Date, default: Date.now },
modifiedDate: { type: Date, default: Date.now },
name: { type: String, default: Date.now },
description: { type: String },
parentId: { type: ObjectId, ref: 'Project' },
// Variables
componentVariables: [componentVariableSchema],
simulationVariables: [simulationVariableSchema],
// Integrator
integratorType: { type: String },
integratorParams: [Number],
// Conditions
startTime: 0,
stopTime: 0,
initialValues: [Number],
// Containers for the code portion of the simulation
initializationCode: { type: String },
preFireCommandCode: { type: String },
staveVariableDerivativesCode: { type: String },
postFireCommandCode: { type: String },
// A simulation can be run multiple times with different sets of results
resultsList: [simulationResultSchema],
createdByUserId: { type: ObjectId, ref: 'User' },
isViewableToOthers: Boolean,
deletedBy: { type: ObjectId },
deletedDate: { type: Date }
},
{
timestamps: true
});
simulationVariables数组也有同样的问题。父对象simulationSchema位于其父对象的数组中,但所有成员变量看起来都正确。我以前从未见过这种情况,我也不知道是什么原因造成的。
这就是我的…
,这就是Chrome显示的…
好吧,但你的问题是什么?我不明白你面临的问题是什么?取回时您是否收到错误的文档?或者您的文档保存格式不正确。请正确说明问题我的错误,漫长的一天。问题是对象中的键被方括号包围,例如[isStateVariable]
而不是isStateVariable
。当我将它们保存在数据库中时,键的名称包括括号。结构中的其他键没有括号。