I would like to update a massive set of documents on an hourly basis.
Here's a pretty simple Model:
class Article
include Mongoid::Document
field :article_nr, :type => Integer
field :vendor_nr, :type => Integer
field :description, :type => String
field :ean
field :stock
field :ordered
field :eta
so every hour I get a fresh list of stocks, where: stocks ,: are ordered and: eta "may" has changed and I need to update them all.
Edit: the list contains only
:article_nr, :stock, :ordered, :eta
where do I parse the hash
In SQL, I would select the article_nr foreign key path to the stock table, discarding the entire stock table and running collection.insert or something like that
But this approach does not seem to work with manga. Any hints? I can't get my head around collection.update and changing the foreign key to belongs_to and has_one doesn't seem to work (tried it, but then Article.first.stock was zero)
But there should be a faster way than iterating over an array of hashes and something like
Article.where( :article_nr => stocklist['article_nr']).update( stock: stocklist['stock'], eta: stocklist['eta'],orderd: stocklist['ordered'])