-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
-
None
I am using mongodb with 3 shard clusters and Mongoid 2.4.6
I found a problem when saving object using 'new' and 'save' method. (But, Create method works well.)
There a Place model which use _id and pioneer_id for shard keys like below.
48 index(
49 [
50 [ :_id, Mongo::ASCENDING],
51 [ :pioneer_id, Mongo::ASCENDING]
52 ]
53 )
54
55 shard_key :_id, :pioneer_id
This is an error code :
@spot = Place.new
@spot.name = 'blabla'
@spot.latitude = '47.2323'
@spot.longitude = '37.222'
...
@spot.save <--- save result is true, but mongos log is like below.
tried to insert object with no valid shard key: atsay.places { _id: ObjectId('4f73eb3157ad151e1bfeece2'), _id: ObjectId('4f73eb30b66bca6f32000003'), is_client: false, is_hotspot: false, is_deleted: false, pageview: 0, total_visitor: 0, recent_articles_count: 0, fan_ids: {}, written_user_ids: {}, name: "Boramae-hospital", address: "Seoul Korea ", longitude: 126.924051, latitude: 37.493273, gps: [ 37.493273, 126.924051 ], updated_at: new Date(1332996913000), created_at: new Date(1332996913000) }
There are duplicate '_id' field!
I can't understand why the '_id' filed inserted twice.
But @spot = Place.create(:name => 'zzz', :latitude => 37.2323 ..... ) <-- It works.
Use 'new' and 'save' is diffirent to 'create'?
It is a mongoid problem?