You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

关于使用Orion CB与Cygnus向MongoDB写入浮点/双精度型数据的咨询

Storing Float/Double Data in MongoDB via Orion CB & Cygnus

Absolutely, you can store numerical data (like water quality metrics or usage values) as float/double types in MongoDB using Orion Context Broker and Cygnus—this is fully supported, and it’s straightforward to set up once you know the key steps.

Here’s how to make it work:

1. Define Entity Attributes with Correct Type in Orion

Orion uses JSON Schema types, so when creating or updating your water-related entities, explicitly set the attribute type to Number (this covers both float and double values, since MongoDB stores all numeric non-integer values as double by default, which is perfect for your use case).

Example POST request to create an entity:

POST /v2/entities
Content-Type: application/json

{
  "id": "WaterSensor_001",
  "type": "WaterMonitor",
  "pH": {
    "value": 7.4,
    "type": "Number"
  },
  "dailyUsage": {
    "value": 125.6,
    "type": "Number"
  },
  "turbidity": {
    "value": 0.32,
    "type": "Number"
  }
}

If you need to update an existing attribute from string to numeric, use a PUT request targeting the specific attribute:

PUT /v2/entities/WaterSensor_001/attrs/pH
Content-Type: application/json

{
  "value": 7.3,
  "type": "Number"
}

2. Configure Cygnus to Preserve Data Types

Cygnus will automatically pass through the numeric type from Orion to MongoDB as long as you’re using a recent version (0.10.0+) and your sink configuration doesn’t force string conversion.

Key configuration checks in your cygnus.conf for the MongoDB sink:

  • Ensure mongodb_attr_persistence is set to row (the default) or column—both preserve type information.
  • Avoid any custom converters that might cast values to strings.

3. Verify the Data Type in MongoDB

After sending data through Orion and Cygnus, confirm the type in MongoDB using the shell:

db.WaterMonitor.findOne({id: "WaterSensor_001"})

You should see output where numeric attributes are stored as doubles, not strings:

{
  "_id": ObjectId("..."),
  "id": "WaterSensor_001",
  "type": "WaterMonitor",
  "pH": 7.4,
  "dailyUsage": 125.6,
  "turbidity": 0.32,
  // other metadata fields
}

A quick note: MongoDB doesn’t have a distinct float type—all non-integer numeric values are stored as double, which is more than sufficient for water quality and usage metrics.

内容的提问来源于stack exchange,提问作者Miguel Collado Quesada

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 04:08:38