如何将一个字段添加到基于同一集合中一个字段的蒙哥达集合中?
如何根据同一集合中的字段将字段添加到MongoDB集合中?例如,在此集合中:
{"_id" : "Apple", "colour": "green"}
{"_id" : "Apple", "colour": "red"}
我想在“ iSgreen”集合中添加第三个字段,所以看起来像这样:
{"_id" : "Apple", "colour" : "green", "isGreen" : "yes"}
{"_id" : "Apple", "colour" : "red", "isGreen" : "no"}
通过聚合可以做到这一点?
How can I add a field to a MongoDB collection based on a field in the same collection? For example, in this Collection:
{"_id" : "Apple", "colour": "green"}
{"_id" : "Apple", "colour": "red"}
I would like to add a third field in the collection "isGreen" so it would look like this:
{"_id" : "Apple", "colour" : "green", "isGreen" : "yes"}
{"_id" : "Apple", "colour" : "red", "isGreen" : "no"}
Is this possible with an aggregation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
$ set
带有$ cond
操作员的阶段。示例mongo playground
Use
$set
stage with$cond
operator.Sample Mongo Playground