【发布时间】:2015-06-11 05:55:38
【问题描述】:
使用 upsert 时我无法将 new_data 推送到数组中
如何使用 upsert 插入/更新一个文档?
history 是一个数组。
顺便说一句,宝石mongo 的数据'似乎远不如Python 或Javascript 受欢迎。
gemmongo是不是比其他语言功能少,bug多?
ArgumentError:参数数量错误(1..2 为 3)
[64] pry(#<Scoot>)> @db.data_collection.find({_id: data[:_id]}).update_one(
[64] pry(#<Scoot>)* {data: data,
[64] pry(#<Scoot>)* from: from_city,
[64] pry(#<Scoot>)* },
[64] pry(#<Scoot>)* {:$push => { "history" => new_data }},
[64] pry(#<Scoot>)* :upsert => true,
[64] pry(#<Scoot>)* :safe => true
[64] pry(#<Scoot>)* )
ArgumentError: wrong number of arguments (3 for 1..2)
Mongo::Error::OperationFailure: '$push' 中的美元 ($) 前缀字段 '$push' 对存储无效。 (52)
@db.data_collection.find({_id: data[:_id]}).update_one(
{data: data,
from: from_city,
:$push => { "history" => new_data },
},
:upsert => true,
:safe => true
)
更新 GEM MONGO 2.0.4
collection.find({_id: data[:_id]}).update_one(
{
"$set" => {
"city" => from_city
},
"$push": => { "history" => new_data }
},
:upsert => true
)
错误
SyntaxError: unexpected tSTRING_DEND, expecting end-of-input
[105] pry(#<Scoot>)> :upsert => true
SyntaxError: unexpected =>, expecting end-of-input
:upsert => true
^
[105] pry(#<Scoot>)> )
SyntaxError: unexpected ')', expecting end-of-input
【问题讨论】: