Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Mongodb,rails修改非数组调试类?阵列>&燃气轮机;真的_Ruby On Rails_Mongodb_Mongomapper - Fatal编程技术网

Ruby on rails Mongodb,rails修改非数组调试类?阵列>&燃气轮机;真的

Ruby on rails Mongodb,rails修改非数组调试类?阵列>&燃气轮机;真的,ruby-on-rails,mongodb,mongomapper,Ruby On Rails,Mongodb,Mongomapper,我一直在尝试添加到一个数组(或者ruby所说的是一个数组),但不断从mongo得到一个错误,它说 Cannot apply $addToSet modifier to non-array 无法将$addToSet修饰符应用于非数组 当我试着跑的时候 User.collection.update({'id'=> current.id},{'$addToSet'=>{ 'following' => current.id}}) User.collection.update({'id'=> us

我一直在尝试添加到一个数组(或者ruby所说的是一个数组),但不断从mongo得到一个错误,它说

Cannot apply $addToSet modifier to non-array 无法将$addToSet修饰符应用于非数组 当我试着跑的时候

User.collection.update({'id'=> current.id},{'$addToSet'=>{ 'following' => current.id}}) User.collection.update({'id'=> user.id},{'$addToSet'=>{ 'following' => user.id}}) 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.push\u uniq(current.id,:following=>User.id) User.push_uniq(User.id,:followers=>current.id) 当我输出

<%= debug @user.following.kind_of? Array %> 返回true

但是,在运行时

db.users.find() db.users.find() 直接对mongo,我明白了

{ "_id" : ObjectId("4c4a196f15a79004e0000007"), "email" : "test@test.com", "foll owers" : null, "following" : null, "password_hash" : "98f2188de42bce1554d08fbc81 d5c99a2c234933", "password_salt" : "25d80a83cfe3d126cdbe9fec2b731ab9ea57c3b8", " username" : "test" } {“_id”:ObjectId(“4c4a196f15a79004e0000007”),“电子邮件”:test@test.com“,”富利 owers“:null,“following“:null,“password_hash”:“98f2188de42bce1554d08fbc81 d5c99a2c234933,“密码”:“25d80a83cfe3d126cdbe9fec2b731ab9ea57c3b8” 用户名“:“测试”} 我希望follower和followers是[],而不是null

当我输出debug@user.followers时,rails显示---[]

我创建用户的模型是

key :username, :type => String key :email, :type => String key :password_hash, :type => String key :password_salt, :type => String key :followers, :type => Array key :following, :type => Array 键:username,:type=>String 关键字:email,:type=>String key:password\u hash,:type=>String key:password\u salt,:type=>String 键:followers,:type=>Array 关键字:following,:type=>Array 该错误使我相信正在找到user.followers,但无法更新。 当我改变

User.push_uniq(current.id, :testing => user.id) User.push_uniq(current.id,:testing=>User.id) 我没有错,所以我想我把那个部分搞对了。
有什么建议吗?

这与mongomapper中的键定义有点不一致

不要对数组使用:type=>限定符


我删除了整个集合,删除了:type,并重新创建了所有内容,现在一切正常了

当使用
key:following,Array
而不是
key:following,:type=>Array
声明密钥时,这适用于be in 0.8


我同时尝试了
push\u uniq
collection.update
,两种方法都没有出现错误。在您的
集合.update
示例中,您确实需要使用
\u id:value
而不是
id:value
,因为该命令直接传递给mongo。

这看起来像是MongoMapper中的一个潜在错误。我建议把这个发到MM谷歌集团。正如您所发现的,数据库中的字段首先需要是一个数组。