查找满足条件的子记录并合并

【问题】

Trying to find the dataList rows that have the first element in the string array greater than 6154 and less than or equal to 6155. Is it possible using MongoDB. For example I am expecting mongoDB to return the rows: “6154.5,37.9,1.529,1.429,1.429”,

“6155,30.4,1.505,1.532,1.543”,

Collection which has the following structure:

{
        “_id” : ObjectId(“54f6a766bf4436333edcd6a2”),
        “_class” : “com.abc.core.bo.obj.Objs”,
        “objList” : [
                {
                        “name” : “ABB-09”,
                        “uid” : “ABB-09”,
                        “data” : {
                                “dataId” : NumberLong(0),
                                “dataList” : [
            “6150,32.9,1.475,,1.434”,
            “6150.5,43,,1.529,1.402”,
            “6151,31.8,1.506,1.447,1.453”,
            “6151.5,33.6,1.481,1.456,1.521”,
            “6152,30.9,1.465,1.472,1.547”,
            “6152.5,39.5,1.404,1.425,1.485”,
            “6153,43.2,1.406,1.446,1.481”,
            “6153.5,39.5,1.433,1.468,1.488”,
            “6154,32.7,1.459,1.477,1.427”,
            “6154.5,37.9,1.529,1.429,1.429”,
            “6155,30.4,1.505,1.532,1.543”,
            “6155.5,37.3,1.49,1.436,1.462”,
            “6156,35.3,1.538,1.45,1.488”,
            “6156.5,37.3,1.517,1.535,1.473”,
            “6157,32.7,1.401,1.405,1.497”,
            “6157.5,38.9,1.488,1.468,1.499”,
            “6158,35.4,1.526,1.422,1.452”,
            “6158.5,43.3,1.516,1.433,1.491”,
            “6159,34.6,1.519,1.442,1.478”,
            “6159.5,42.7,1.426,1.514,1.428”,
      “6160,32.7,1.451,1.5,1.516”
            ]
           }
          }] }

【回答】

问题是,要将 mongodb 中的一系列字符串记录按照逗号分割的首个数字值筛选。直接使用 Mongodb 的 API 应该可以实现这个需求,但会比较繁琐,可以考虑用 SPL 解决:

A

1

=mongo_open(“mongo://localhost:27017/local?user=test&password=test”)

2

=mongo_shell(A1,”test35.find()”)

3

=A2.objList.data.dataList

4

=A3.select(~.split@cp()(1) > 6154 && ~.split@cp()(1) <= 6155)

5

>mongo_close(A1)

A3:找到需要计算的数据序列

A4:将每个字符串成员转成序列,取第一个子成员,根据其选择数据

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值