我无法将常规对象推送到猫鼬中的混合字段数组。
我正在尝试这个:
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
)
)
完全不是我所期望的。怎么了?
首先我创建“原始数据”模式:(这里我使用一个空对象文字,我也使用了 Schema.Types.Mixed 一个)
{ rawdata: { type: {} } }
然后我将它添加到更大的模式中,结果如下:
rawdata:
[ { paths: [Object],
subpaths: {},
virtuals: [Object],
nested: {},
inherits: {},
callQueue: [],
_indexes: [],
methods: {},
statics: {},
tree: [Object],
_requiredpaths: undefined,
options: [Object] } ],