模块:Mongoid::CollectionConfigurable::ClassMethods
- 定义于:
- lib/mongoid/collection_configurable.rb
实例方法摘要折叠
-
# create_collection (force: false) ⇒ 对象
为调用的 Mongoid 模型创建集合。
实例方法详细信息
# create_collection (force: false) ⇒对象
为调用的 Mongoid 模型创建集合。
此方法不会重新创建现有集合。
如果 document 包含带有 collection_options 键的 store_in 宏,则在创建集合时使用这些选项。
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/mongoid/collection_configurable.rb', line 22 def create_collection(强制: false) if collection_name.空? # 这很可能是一个匿名类,我们忽略它们。 return end if / ^system\. /.匹配?(collection_name) # 我们不对系统集合执行任何操作。 return end 集合.删除 if force if = 集合.database.list_collections(过滤器: { 名称: collection_name.to_s }).first 提高 Errors::DropCollectionFailure.new(collection_name) if force 记录器.debug( " MONGOID: Collection ' #{ collection_name } '已经存在" + " in 数据库 ' #{ database_name } ' with options ' #{ } '. " ) else 开始 集合.database[collection_name, .获取(:collection_options, {})].创建 救援 mongo::错误::OperationFailure => e 提高 Errors::CreateCollectionFailure.new( collection_name, [:collection_options], e ) end end end |