我正在尝试使用 MongoDB 作为我的数据库来构建基于 Roda 的(非 Rails)API。我安装了 Mongoid gem 并配置了连接。不幸的是,当我尝试使用创建定义的索引时rake db:mongoid:create_indexes
,由于缺少索引,任务失败environment
。Rakefile
为了提供所需的任务,我应该做什么/包括什么?
回溯:
rake aborted!
Don't know how to build task 'environment' (See the list of available tasks with `rake --tasks`)
/home/tomasz/.rvm/gems/ruby-2.7.1/bin/ruby_executable_hooks:24:in `eval'
/home/tomasz/.rvm/gems/ruby-2.7.1/bin/ruby_executable_hooks:24:in `<main>'
Tasks: TOP => db:mongoid:create_indexes
(See full trace by running task with --trace)
我的相关部分Rakefile
:
require 'mongoid'
path = Gem::Specification.find_by_name('mongoid')
load "#{path.gem_dir}/lib/mongoid/railties/database.rake"
rake -T
输出:
rake db:create_indexes # Create indexes specified in Mongoid models
rake db:drop # Drops all the collections for the database for the current Rails.env
rake db:mongoid:create_indexes # Create indexes specified in Mongoid models
rake db:mongoid:drop # Drop the database of the default Mongoid client
rake db:mongoid:purge # Drop all non-system collections
rake db:mongoid:remove_indexes # Remove indexes specified in Mongoid models
rake db:mongoid:remove_undefined_indexes # Remove indexes that exist in the database but are not specified in Mongoid models
rake db:mongoid:shard_collections # Shard collections with shard keys specified in Mongoid models
rake db:purge # Drop all collections except the system collections
rake db:remove_indexes # Remove indexes specified in Mongoid models
rake db:reset # Delete data and loads the seeds
rake db:seed # Load the seed data from db/seeds.rb
rake db:setup # Create the database, and initialize with the seed data
rake db:shard_collections # Shard collections with shard keys specified in Mongoid models