私は配列に追加しようとしています(またはRubyが言っているのは配列です)が、mongoから次のようなエラーが発生し続けます
$addToSet 修飾子を非配列に適用できません
走ろうとすると
User.collection.update({'id'=> current.id},{'$addToSet'=>{ 'following' => current.id}}) User.collection.update({'id'=> user.id},{'$addToSet'=>{ 'following' => user.id}})
またはmongomapperバージョン
User.push_uniq(current.id, :following => user.id) User.push_uniq(user.id, :followers => current.id)
出力すると
<%= デバッグ @user.following.kind_of? 配列 %>
true を返します
ただし、実行時は
デシベル.ユーザー.find()
モンゴに直接、私は得る
{ "_id" : ObjectId("4c4a196f15a79004e0000007"), "email" : "test@test.com", "フォロー owers": null、"following": null、"password_hash": "98f2188de42bce1554d08fbc81 d5c99a2c234933", "password_salt": "25d80a83cfe3d126cdbe9fec2b731ab9ea57c3b8"," ユーザー名": "テスト" }
私は、フォローとフォロワーが null ではなく [] であることを期待していました。
debug @user.followers を出力すると、rails は --- [] を表示します。
ユーザーを作成するための私のモデルは
キー:ユーザー名、:タイプ => 文字列 キー :email, :type => 文字列 キー :password_hash, :type => 文字列 キー :password_salt, :type => 文字列 key :followers, :type => 配列 key :following, :type => 配列
このエラーにより、user.followers は見つかったものの、更新できないと思われます。私が変わるとき
User.push_uniq(current.id, :testing => user.id)
エラーが出ないので、その部分は正しいと思います。助言がありますか?