MongoDB将字符串从两个字段串联到第三个字段 [英] MongoDB concatenate strings from two fields into a third field

查看:231
本文介绍了MongoDB将字符串从两个字段串联到第三个字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何连接两个字符串字段中的值并将其放入第三个字符串字段中?

我已经尝试过了:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆