MongoDB将字符串从两个字段串联到第三个字段 [英] MongoDB concatenate strings from two fields into a third field
问题描述
如何连接两个字符串字段中的值并将其放入第三个字符串字段中?
我已经尝试过了:
db.collection.update(
{ "_id": { $exists: true } },
{ $set: { column_2: { $add: ['$column_4', '$column_3'] } } },
false, true
)
似乎不起作用,并抛出not ok for storage
.
我也尝试过:
db.collection.update(
{ "_id": { $exists : true } },
{ $set: { column_2: { $add: ['a', 'b'] } } },
false, true
)
但即使这样也显示相同的错误not ok for storage
.
我只想在mongo服务器上串联,而不要在我的应用程序中串联.
不幸的是,MongoDB当前不允许您在执行update()时引用任何字段的现有值.现有的Jira票证可以添加此功能:有关详细信息,请参见 SERVER-1765 . /p>
目前,您必须进行初始查询以确定现有值,并在客户端中进行字符串操作.希望我能为您提供更好的答案.
How do I concatenate values from two string fields and put it into a third one?
I've tried this:
db.collection.update(
{ "_id": { $exists: true } },
{ $set: { column_2: { $add: ['$column_4', '$column_3'] } } },
false, true
)
which doesn't seem to work though, and throws not ok for storage
.
I've also tried this:
db.collection.update(
{ "_id": { $exists : true } },
{ $set: { column_2: { $add: ['a', 'b'] } } },
false, true
)
but even this shows the same error not ok for storage
.
I want to concatenate only on the mongo server and not in my application.
Unfortunately, MongoDB currently does not allow you to reference the existing value of any field when performing an update(). There is an existing Jira ticket to add this functionality: see SERVER-1765 for details.
At present, you must do an initial query in order to determine the existing values, and do the string manipulation in the client. I wish I had a better answer for you.
这篇关于MongoDB将字符串从两个字段串联到第三个字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!