Mongoid package update

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'])
+5
2

# update_all. $ , .

 # Update all people with last name Oldman with new first name.
 Person.where(last_name: "Oldman").update_all(
first_name: "Pappa Gary"
 )

. - , , nr uniq.

class Article
  include Mongoid::Document
  field :article_nr
  field :name
  key :article_nr

  has_many :stocks
end

class Stock
  include Mongoid::Document
  field :article_id
  field :eta
  field :ordered
  belongs_to :article
end

:

Stock.create(:article_id => "123", :eta => "200")

article_nr = > "123" , .

my_article.stocks.last

: article_nr , : after_save new_stock.article_id = new_stock.article_nr

, - , , , .

+10

(, has_one ), mongoimport -upsertFields, article_nr upsertField. . http://www.mongodb.org/display/DOCS/Import+Export+Tools.

0

All Articles