Mongoid 上限集合

问题描述 投票:0回答:2

我正在尝试使用 Mongoid 创建一个上限集合。我有一个定义如下:

class Customer
  include Mongoid::Document
  store_in(collection: 'customers')

  field: n, type: String, as: :name
  field: a, type: String, as: :address
  field: z, type: String, as: :zip
end

我一直在参考文档,但无法弄清楚如何在这部分代码中创建上限集合。我尝试删除

store_in
行并用
session.command(create: "customers", capped: true, size: 10000000, max: 1000)
替换它,但无济于事。
session
应该用什么东西代替吗?还是我的做法不正确?

ruby mongoid capped-collections
2个回答
0
投票

Mongoid 不提供动态创建上限集合的机制 - 您需要通过 Mongo 控制台自己创建这些集合。


0
投票

复活这个,因为这是“Mongoid capped collection”的第一个 Google 结果。

Mongoid 现在提供指定上限集合的功能:文档

class Name
  include Mongoid::Document
  store_in collection_options: {
    capped: true,
    size: 1024 # in bytes
  }
end
© www.soinside.com 2019 - 2024. All rights reserved.