Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我应该如何在mongodb中存储我的性能对象?_Mongodb_Mongoose - Fatal编程技术网

我应该如何在mongodb中存储我的性能对象?

我应该如何在mongodb中存储我的性能对象?,mongodb,mongoose,Mongodb,Mongoose,我应该如何存储对象以实现性能 我的应用程序中的每个用户都有一个bucket。在水桶里,他有一系列的物品 我不想将其存储在用户集合中(因为在检索用户时我不需要这些数据) 一种方法是按存储桶的名称存储: const BucketSchema = new Schema( { name: { type: String }, user: { type: mongoose.Schema.Types.ObjectId, ref: 'User' }, items: [{ type:

我应该如何存储对象以实现性能

我的应用程序中的每个用户都有一个bucket。在水桶里,他有一系列的物品

我不想将其存储在用户集合中(因为在检索用户时我不需要这些数据)

一种方法是按存储桶的名称存储:

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' }],
        }]
      },
    );

还是没关系?

这在很大程度上取决于您将要执行的读写操作。