Skip to content

Add index creation on startup. #896

@mapedraza

Description

@mapedraza

According to the Docker instructions, it is required to create 2 indexes on MongoDB

```console
docker exec <mongo-db-container-name> mongo --eval '
conn = new Mongo();
db = conn.getDB("iotagentjson");
db.createCollection("devices");
db.devices.createIndex({"_id.service": 1, "_id.id": 1, "_id.type": 1});
db.devices.createIndex({"_id.type": 1});
db.devices.createIndex({"_id.id": 1});
db.createCollection("groups");
db.groups.createIndex({"_id.resource": 1, "_id.apikey": 1, "_id.service": 1});
db.groups.createIndex({"_id.type": 1});' > /dev/null
```

It would be great if the IoTA could create them by itself (for example, at startup time).

It should check if collections are present and:

  • If yes, check if the index already exists:
    • If yes, continue with normal execution
    • If no, try to creates the indexes
      • If succes, continues the normal execution
      • If fail, it should print an error log and continues the normal execution. This is really important because in some legacy installations, it could be present duplicated devices and fail to create the index. In that case, the IoTA should run as usual.

Not sure if it is part of the IoTA JSON or Library. Probably It can be addresed as part of the docker entrypoint, but also as part of the nodejs code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions