我有以下对象数组。目前,它有一个对象,其中包含多个对象。
let arr =
[
{
"data": {
"Score": {
"score": [
"87",
"21"
],
"Player": [
"Wiki",
"Tim"
]
},
"Designation": {
"By": [
"0",
"0",
"1",
"0",
"0"
],
"Position": [
"31/07/17",
"31/07/17",
"31/07/17",
"31/07/17",
"31/07/17"
]
},
"Address": {
"Location": "London",
"House_No": "43-B",
}
}
}
]上面的数据将放在一个表中。
我尝试过循环和插入,但没有找到任何方法。上面的数据不是常量,就像Position有5个元素一样,下一次可以是6,所以我不能简单地通过它的索引插入它。
我试过了,但没有成功。
发布于 2017-11-20 01:19:56
在Mongodb中,如果你有动态数据,你可以使用混合类型模式,如下所示:
details:Schema.Types.Mixed,示例模式:-
// grab the things we need
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var mongoosePaginate = require('mongoose-paginate');
// create a schema
var casesSchema = new Schema({
sku: {type:String, unique:true},
details:Schema.Types.Mixed,
created_at: {type:Date, default: Date.now},
images: Schema.Types.Mixed,
ebay_hosted_images: Schema.Types.Mixed,
cloudinary_hosted_images: Schema.Types.Mixed,
dropbox_hosted_images: Schema.Types.Mixed,
is_listed:Boolean,
user_id : {type: String, ref:'User'}
});
casesSchema.plugin(mongoosePaginate);
var cases = mongoose.model('cases', casesSchema);
module.exports = cases;https://stackoverflow.com/questions/47379196
复制相似问题