Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating indexes from the console with an empty DB crashes with "ns does not exist" #47

Open
Startouf opened this issue Aug 2, 2021 · 4 comments
Labels

Comments

@Startouf
Copy link

Startouf commented Aug 2, 2021

Context : starting a mongoid container/pod on kubernetes and trying to seed the database with

::Mongoid::Tasks::Database.create_indexes
# or rails db:create_indexes

I am not sure whether this is due to a Mongoid update or something else I am missing.
Backtrace

rails aborted!
Mongo::Error::OperationFailure: ns does not exist: my_db_production.mongoid_fulltext.index_collection_name_0 (26) (on mongodb.staging.svc.cluster.local, modern retry, attempt 1)
/usr/local/bundle/gems/mongo-2.14.0/lib/mongo/operation/result.rb:343:in `raise_operation_failure'
/usr/local/bundle/gems/mongo-2.14.0/lib/mongo/operation/indexes/result.rb:86:in `validate!'
/usr/local/bundle/gems/mongo-2.14.0/lib/mongo/operation/shared/response_handling.rb:29:in `block (3 levels) in validate_result'
/usr/local/bundle/gems/mongo-2.14.0/lib/mongo/operation/shared/response_handling.rb:96:in `add_server_diagnostics'
/usr/local/bundle/gems/mongo-2.14.0/lib/mongo/operation/shared/response_handling.rb:28:in `block (2 levels) in validate_result'
/usr/local/bundle/gems/mongo-2.14.0/lib/mongo/operation/shared/response_handling.rb:43:in `add_error_labels'
/usr/local/bundle/gems/mongo-2.14.0/lib/mongo/operation/shared/response_handling.rb:27:in `block in validate_result'
/usr/local/bundle/gems/mongo-2.14.0/lib/mongo/operation/shared/response_handling.rb:82:in `unpin_maybe'
/usr/local/bundle/gems/mongo-2.14.0/lib/mongo/operation/shared/response_handling.rb:26:in `validate_result'
/usr/local/bundle/gems/mongo-2.14.0/lib/mongo/operation/shared/executable.rb:46:in `block in execute'
/usr/local/bundle/gems/mongo-2.14.0/lib/mongo/operation/shared/executable.rb:45:in `tap'
/usr/local/bundle/gems/mongo-2.14.0/lib/mongo/operation/shared/executable.rb:45:in `execute'
/usr/local/bundle/gems/mongo-2.14.0/lib/mongo/operation/shared/op_msg_or_list_indexes_command.rb:29:in `block 

The faulty lines of code (School collection is empty)

School.all.each(&:save)
::School.create_indexes
@dblock dblock added the bug? label Aug 2, 2021
@selivandex
Copy link

same here

@selivandex
Copy link

@Startouf did you found the solution?

@Startouf
Copy link
Author

Startouf commented Nov 22, 2021

No we haven't really found a solution yet. We just ensure there is something in the collection before running create_indexes.

For example, we had some mongoid migration code where we had to add a guard clause return if MyCollection.empty? in the self.up method to avoid problems in test apps with an empty database
Screenshot 2021-11-22 at 15 01 56

@selivandex
Copy link

No we haven't really found a solution yet. We just ensure there is something in the collection before running create_indexes.

For example, we had some mongoid migration code where we had to add a guard clause return if MyCollection.empty? in the self.up method to avoid problems in test apps with an empty database

I just realised that starting from mongoid 4 there is a built-in full text search and you just need to create index:

index searchable_field: 'text'

then search: Model.text_search('query')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants