2017-08-08 18 views
0

Ich aktualisiere eine Rails 4.2 App mit Mongoid 5.2, aber nach dem Upgrade finde ich, dass options, client Feldnamen nicht erlaubt sind.Mongoid 6 Alias ​​Feldname

Zu diesem Schluss kommt ich kam nach an mongoid Code suchen und zu sehen, diese Ausnahme:

Nameerror - nicht definierte Methode options' for class ScheduledReport ': mongoid (6.1.1) lib/mongoid/errors/invalid_field.rb : 44: in 'Herkunft'

Gibt es eine Möglichkeit, ein Feld zu definieren: foo, das zugeordnet wird: Optionen oder welches Feld in der Datenbank?

Das ist meine Bestimmung des Modells:

class ScheduledReport 
    include Mongoid::Document 

    field :options, type: Hash, default: {} 
end 

Vielen Dank im Voraus!

Antwort

0

ich fand keine Lösung die Feldnamen auf der Karte, so habe ich beschlossen, mit Migrations das Feld zu benennen, da die betroffenen Sammlungen klein sind:

collection = Mongoid.default_client[:scheduled_reports] 
collection.find.each do |report| 
    puts "#{report['options']} => #{report['configuration']}" 
    if report['options'] 
    collection.update_one({ '_id' => report['_id'] }, { '$set' => { 'configuration' => report['options'] } }) 
    object = collection.find('_id' => report['_id']).first 
    puts "#{object['options']} => #{object['configuration']}" 
    end 
end