-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
-
None
Hello. I'm using Mongoid (3.0.3).
class Tracker include Mongoid::Document include Mongoid::Timestamps field :name, type: String field :status, type: String end
t1 = Tracker.create!(name: "David") t2 = Tracker.new(name: "David") t2.upsert Tracker.count # => 2
Unable to find source-code formatter for language: log. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
MOPED: 127.0.0.1:27017 INSERT database=example_development collection=trackers documents=[{"_id"=>"5024580b60e18c2b4a000001", "name"=>"David", "updated_at"=>2012-08-10 00:38:35 UTC, "created_at"=>2012-08-10 00:38:35 UTC}] flags=[] (0.2310ms) MOPED: 127.0.0.1:27017 UPDATE database=example_development collection=trackers selector={"_id"=>"5024586560e18c2b4a000002"} update={"_id"=>"5024586560e18c2b4a000002", "name"=>"David"} flags=[:upsert] (0.1531ms) MOPED: 127.0.0.1:27017 COMMAND database=example_development command={:count=>:trackers, :query=>{}} (0.5820ms)
I want there to be only be 1 Tracker. Notice how t2 has a different _id than t1.
I'm looking for atomic upsert behavior like Mongo's db.collection.findAndModify. Do you intend Mongoid's upsert to be similar?