保存二维阵列的最佳方法是什么,我生成的问题是因为它不是小阵列。那么有没有办法将这个2D数组转换为某种JSON格式或者其他东西,然后用mongoose保存,然后快速转换回来,其中的值是字符串,所有的想法都很受欢迎。
这是我的架构:
var UserRatingSchema = new Schema({
user: {type: mongoose.Schema.Types.ObjectId, ref: 'User'},
movie: {type: mongoose.Schema.Types.ObjectId, ref: 'Movie'},
rating: String,
});
数组的例子:
[无] Movie1 Movie2
User1 10没有评级
User2 6 5
...
如果我将每个实例保存到数据库是否有效?
答案 0 :(得分:1)
你可以定义这样的模型,
location: {type: [Number]}
并在模式索引中定义,如
UserSchema.index({location : '2d'});
现在你的结构就像这样
"location": [
67.0783412,
24.9044033
]
您也可以通过向值添加键来修改!