Search code examples
fiwarefiware-cygnus

Multiple entities can't be saved at same time in Mongo historical database


I am trying to save multiple data entities in historical database, but only the first one from the array is saved in Mongo historical database. Below are the steps I performed.

Docker-compose for Cygnus:

 version: "3.8"
 services:
   cygnus:
    hostname: cygnus
    container_name: cygnus
    image: fiware/cygnus-ngsi:2.16.0
    networks:
     - default_config
    ports:
     - "5080:5080"
     - "5051:5051"
    expose:
     - "5051"
     - "5080"
    environment:
     - CYGNUS_MONGO_SERVICE_PORT=5051
     - CYGNUS_MONGO_HOSTS=mongo_db:27017
     - CYGNUS_MONGO_USER=root
     - CYGNUS_MONGO_PASS=root
     - CYGNUS_MONGO_AUTH_SOURCE=admin
     - CYGNUS_MONGO_DATA_MODEL=dm-by-service-path
     - CYGNUS_MONGO_ATTR_PERSISTENCE=column
     - CYGNUS_SERVICE_PORT=5051
     - CYGNUS_API_PORT=5080
     - CYGNUS_LOG_LEVEL=DEBUG
     - CYGNUS_ORION_HOST=orion
     - CYGNUS_ORION_PORT=1026
     - CYGNUS_ORION_SSL=true
 networks:
   default_config:
     external: true

Create a Cygnus subscription:

curl --location --request POST 'http://localhost1026/v2/subscriptions' \
--header 'Content-Type: application/json' \
--data-raw '{
  "description": "Notify Cygnus Mongo-DB of all context changes",
  "subject": {
    "entities": [
      {
        "idPattern": ".*"
      }
    ]
  },
  "notification": {
    "http": {
      "url": "http://10.0.0.5:5051/notify"
    }
  },
  "throttling": 5
}'

Batch Create a New Data Entity :

curl --location --request POST 'http://localhost:1026/v2/op/update/' \
--header 'Content-Type: application/json' \
--data-raw '{
  "actionType":"append_strict",
  "entities":[
    {
      "id":"urn:ngsi-ld:Product:100", "type":"Product",
      "name":{"type":"Text", "value":"Brandy"},
      "size":{"type":"Text", "value": "M"},
      "price":{"type":"Integer", "value": 1199}
    },
    {
      "id":"urn:ngsi-ld:Product:101", "type":"Product",
      "name":{"type":"Text", "value":"Port"},
      "size":{"type":"Text", "value": "M"},
      "price":{"type":"Integer", "value": 1099}
    }
  ]
}'

Result in Mongo:

cygnus

Group updates also do not work. Did I miss something in the configuration or there is no possibility for that in Cygnus?

Thank you in advance.


Solution

  • A first impression. At subscription you are using: "throttling": 5

    throttling: Minimal period of time in seconds which must elapse between two consecutive notifications. It is optional.

    That implies that just ONE notificación will be send in every 5 seconds time window. With your NGSIv2 batch update surely all notification will fall in the 5 sec window.

    Try to remove that property.

    https://fiware-orion.readthedocs.io/en/master/user/ngsiv2_implementation_notes/index.html#notification-throttling