NoBrainerORM / nobrainer

Ruby ORM for RethinkDB
http://nobrainer.io/
Other
387 stars 49 forks source link

unable to upsert #259

Closed 34code closed 2 years ago

34code commented 4 years ago

I'm trying the following in my app..

p_ecamp_u = Price.upsert(source: "eCampus.com", condition: "used", amount: 2400, buy_link: "http://www.shareasale.com/r.cfm?u=728790&b=289670&m=13375&afftrack=&urllink=www.ecampus.com/bk_detail.asp?isbn=9780815700258", updated_at: Time.now, item: i, price_id: "eCampus.com_used")

but it gives me the following error:

r.table("nobrainer_locks").get( "KoOu4fXmqxshzg+TgAZes1KSUi0=").replace {|var_12| r.branch( var_12[:instance_token].default(nil).eq("8xxykBb14JBEPJ"), nil, var_12 )}
RethinkDB::ReqlResourceLimitError: Array over size limit `100000`.  To raise the number of allowed elements, modify the `array_limit` option to `.run` (not available in the Data Explorer), or use an index.
Backtrace:
r.table("prices").get_all("eCampus.com_used", {"index" => :price_id}).order_by(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  r.asc(:id)
  ^^^^^^^^^^
).limit(1)
^
from /Users/sambit/.gem/ruby/2.6.5/gems/rethinkdb-2.4.0.0/lib/shim.rb:83:in `rescue in response_to_native'
Caused by RethinkDB::ReqlResourceLimitError: Array over size limit `100000`.  To raise the number of allowed elements, modify the `array_limit` option to `.run` (not available in the Data Explorer), or use an index.

I have checked that the index price_id exists as a secondary index. What am I doing wrong here? I hope this is an error on my part and not nobrainer not supporting upserts on large (20M docs) tables

34code commented 4 years ago

I've found an alternative way to accomplish this.

i.prices.where(price_id: "eCampus.com_used").first.update(amount: 2200) when record exists and Price.create().... when a record does not exist.

Would have really liked to use upsert though

zedtux commented 2 years ago

Coming back on this after having faced the same issue (with kaminari in my case, not upset), I found out that the problem come from the order_by. Using without_ordering avoided that error.

In your case Price.without_ordering.upsert(...) may work, I haven't tested it.

Anyway, the issue is not related to the NoBrainer ORM, nor to the RethinkDB driver, but the RethinkDB database itself so I close this issue. Feel free to update this issue to tell if my solution works for you.