我应该如何在mongodb中存储我的性能对象?
我应该如何存储对象以实现性能 我的应用程序中的每个用户都有一个bucket。在水桶里,他有一系列的物品 我不想将其存储在用户集合中(因为在检索用户时我不需要这些数据) 一种方法是按存储桶的名称存储:我应该如何在mongodb中存储我的性能对象?,mongodb,mongoose,Mongodb,Mongoose,我应该如何存储对象以实现性能 我的应用程序中的每个用户都有一个bucket。在水桶里,他有一系列的物品 我不想将其存储在用户集合中(因为在检索用户时我不需要这些数据) 一种方法是按存储桶的名称存储: const BucketSchema = new Schema( { name: { type: String }, user: { type: mongoose.Schema.Types.ObjectId, ref: 'User' }, items: [{ type:
const BucketSchema = new Schema(
{
name: { type: String },
user: { type: mongoose.Schema.Types.ObjectId, ref: 'User' },
items: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Item' }],
},
);
另一个是储存
const BucketSchema = new Schema(
{
id: { type: objectid },
user: { type: mongoose.Schema.Types.ObjectId, ref: 'User' },
buckets: [{
name: { type: string },
items: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Item' }],
}]
},
);
还是没关系?这在很大程度上取决于您将要执行的读写操作。