根据另一个字段的值更新mongo中的文档字段 [英] Updating a document field in mongo based on another field's value

查看:172
本文介绍了根据另一个字段的值更新mongo中的文档字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有两个字段F1和F2.我想将F1更新为F1 + ", " + F2.我可以在mongo中使用一个更新命令来做到这一点吗?

Suppose I have two fields F1 and F2. I want to update F1 to become F1 + ", " + F2. Can I do so with a single update command in mongo?

推荐答案

不,您不能这样做.您不能在mongodb更新中使用表达式.唯一的方法是将文档获取到客户端,在客户端编写新的字段值并发出准备好的更新语句.

No, you can't do that. You can't use expressions in mongodb updates. The only way is to fetch this document to the client, compose new field value there and issue a prepared update statement.

这篇关于根据另一个字段的值更新mongo中的文档字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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