Skip to content
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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# bedrock-meter ChangeLog

## 6.0.0 -

### Changed
- **BREAKING**: Use `@bedrock/mongodb: ^11`.
- **BREAKING**: Change use of results to match Node Mongo Driver 4 API.

### Removed
- Remove deprecated MongoDB index `background`.

## 5.1.1 - 2022-11-16

### Fixed
Expand Down
13 changes: 8 additions & 5 deletions lib/meters.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ bedrock.events.on('bedrock-mongodb.ready', async () => {
await database.createIndexes([{
collection: 'meter-meter',
fields: {'meter.id': 1},
options: {unique: true, background: false}
options: {unique: true}
}]);
});

Expand All @@ -47,7 +47,7 @@ export async function insert({meter} = {}) {
// store record
const now = Date.now();
const meta = {created: now, updated: now};
let record = {
const record = {
meter: {
...meter,
sequence: 0,
Expand All @@ -59,8 +59,7 @@ export async function insert({meter} = {}) {

try {
const collection = database.collections['meter-meter'];
const result = await collection.insertOne(record);
record = result.ops[0];
await collection.insertOne(record);
record.meter.id = meter.id;
} catch(e) {
if(!database.isDuplicateError(e)) {
Expand Down Expand Up @@ -119,7 +118,11 @@ export async function update({meter, explain = false} = {}) {

const result = await collection.updateOne(
query, {$set}, database.writeOptions);
if(result.result.n === 0) {
// in mongodb driver 4 or greater executionStats are replaced
// n previously counted the number of records that matched a query
// so we need the total of modified and upserted to track record change
const n = result.modifiedCount + result.upsertedCount;
if(n === 0) {
// no records changed...
throw new BedrockError(
'Could not update configuration. ' +
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},
"peerDependencies": {
"@bedrock/core": "^6.0.1",
"@bedrock/mongodb": "^10.0.0"
"@bedrock/mongodb": "^11.0.0"
},
"directories": {
"lib": "./lib"
Expand Down
2 changes: 1 addition & 1 deletion test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@bedrock/core": "^6.0.1",
"@bedrock/express": "^8.0.0",
"@bedrock/meter": "file:..",
"@bedrock/mongodb": "^10.0.0",
"@bedrock/mongodb": "github:digitalbazaar/bedrock-mongodb#mongo-driver-4-rc-fix-duplicate-error",
"@bedrock/server": "^5.0.0",
"@bedrock/test": "^8.0.5",
"bnid": "^3.0.0",
Expand Down