Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Task/align with group uniqueness doc #1665

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- Upgrade express de from 4.19.2 to 4.20.0
- Fix: align group index to align with group uniqueness (iotagent-node-lib#1633,#1589)
- Upgrade express de from 4.19.2 to 4.20.0
3 changes: 3 additions & 0 deletions doc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ Group uniqueness is defined by the combination of: service, subservice, resource
Device uniqueness is defined by the combination of: service, subservice, device_id and apikey. Note that several devices
with the same device_id are allowed in the same service and subservice as long as their apikeys are different.

Note that existent deployments based on previous versions of iotagent-node-lib could use more restrictive unique indexes
in mongodb (specially for groups model) still not updated.

## Special measures and attributes names

In case of arriving measures with name `id` or `type`, they are automatically transformed to `measure_id` and
Expand Down
2 changes: 1 addition & 1 deletion lib/model/Group.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const Group = new Schema({
});

function load(db) {
Group.index({ apikey: 1, resource: 1 }, { unique: true });
Group.index({ apikey: 1, resource: 1, service: 1, subservice: 1 }, { unique: true });
module.exports.model = db.model('Group', Group);
module.exports.internalSchema = Group;
}
Expand Down
12 changes: 8 additions & 4 deletions lib/services/groups/groupRegistryMongoDB.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,25 @@ function createGroup(group, callback) {

logger.debug(
context,
'Storing device group with id [%s], type [%s], apikey [%s] and resource [%s]',
'Storing device group with id [%s], type [%s], apikey [%s], resource [%s], service [%s] and subservice [%s]',
groupObj._id,
groupObj.type,
groupObj.apikey,
groupObj.resource
groupObj.resource,
groupObj.service,
groupObj.subservice
);

groupObj.save(function saveHandler(error, groupDAO) {
if (error) {
if (error.code === 11000) {
logger.debug(
context,
'Duplicate group entry with resource [%s] and apiKey [%s]',
'Duplicate group entry with resource [%s], apiKey [%s], servuce [%s] and subservice %[s]',
group.resource,
group.apikey
group.apikey,
group.service,
group.subservice
);

callback(new errors.DuplicateGroup(group));
Expand Down
Loading