我如何创建“新”广告素材? $ Project从现有字符串中提取字段? [英] How can I create "new" fields from an existing string with $Project?

查看:63
本文介绍了我如何创建“新”广告素材? $ Project从现有字符串中提取字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这种格式的文档:

{_id = ...,描述= Foo Bar Baz | SX = 123 | SY = 456},


{ _id = ..., description = "Foo Bar Baz | SX=123 | SY=456" }, . . .

我必须使用文本字段中提到的值作为SX和SY来提供一些统计信息。

I have to use the values mentioned in the text field as SX and SY to provide some statistics.

是否可以在聚合框架中投影新字段SX和SY,以便我可以在聚合管道中使用这些字段?

Is there any way to "Project" new fields SX and SY within the aggregation framework so I can work with those fields in the aggregation pipeline?

谢谢
Andreas

Thanks Andreas

推荐答案

在MongoDB 2.4上,没有聚合框架运算符,它将分割/解析字符串(根据您的描述字段)。

As at MongoDB 2.4, there is no Aggregation Framework operator that will split/parse a string (as per your example of a description field).

您可以在MongoDB问题跟踪器中观看/更新一些相关的功能请求:

There are a few relevant feature requests that you can watch/upvote in the MongoDB issue tracker:

  • SERVER-6773: Operator for splitting string based on a separator
  • SERVER-8951: Add $find operator for strings
  • SERVER-11947: $project filter using $regex

项目过滤器,直到在聚合框架中实现了上述一个或多个选项之前,您要么必须:

Until one or more of the above options are implemented in the Aggregation Framework, you will either have to:

  • 1) use Map/Reduce for your aggregation query

OR


  • 2)从应用程序代码迭代文档,以便在运行Aggregation Framework查询之前提取并添加所需的其他字段

这篇关于我如何创建“新”广告素材? $ Project从现有字符串中提取字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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