我无法将常规对象推送到mongoose中的混合字段数组。
我正在尝试这个:
ME.update({_id: eventid},
{$push: { rawdata: {x: packet.x, y: packet.y} }},
{upsert:true}, function(err, data) {
console.log(err);
}
});
但是,这只会导致mongodb数据库中的一组id:
[rawdata] => Array (
[0] => Array (
[_id] => MongoId Object (
[$id] => 50f476a13ebe522960000005
)
)
[1] => Array (
[_id] => MongoId Object (
[$id] => 50f476a13ebe522960000006
)
)
[2] => Array (
[_id] => MongoId Object (
[$id] => 50f476a23ebe522960000007
)
)
[3] => Array (
[_id] => MongoId Object (
[$id] => 50f476a23ebe522960000008
)
)
[4] => Array (
[_id] => MongoId Object (
[$id] => 50f476a23ebe522960000009
)
)
[5] => Array (
[_id] => MongoId Object (
[$id] => 50f476a33ebe52296000000a
)
)
[6] => Array (
[_id] => MongoId Object (
[$id] => 50f476a33ebe52296000000b
)
)
[7] => Array (
[_id] => MongoId Object (
[$id] => 50f476a33ebe52296000000c
)
)
完全不是我的预期。出了什么问题?
首先,我创建“rawdata”架构: (这里我使用了一个空对象文字,我也使用了Schema.Types.Mixed一个)
{ rawdata: { type: {} } }
然后我将其添加到更大的架构中,结果类似于:
rawdata:
[ { paths: [Object],
subpaths: {},
virtuals: [Object],
nested: {},
inherits: {},
callQueue: [],
_indexes: [],
methods: {},
statics: {},
tree: [Object],
_requiredpaths: undefined,
options: [Object] } ],