Skip to content

Commit

Permalink
rename mongodb functions see https://github.com/mongodb/node-mongodb-…
Browse files Browse the repository at this point in the history
  • Loading branch information
touv committed Aug 8, 2024
1 parent f888584 commit 319ef32
Show file tree
Hide file tree
Showing 16 changed files with 36 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/api/controller/api/publishFacets.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default async (ctx, fields, withProgress = false) => {
jobLogger.info(ctx.job, 'Publishing facets');

const names = fields.map(({ name }) => name);
await ctx.publishedFacet.remove({ field: { $in: names } });
await ctx.publishedFacet.deleteOne({ field: { $in: names } });

await facetFields
.reduce(
Expand Down
14 changes: 7 additions & 7 deletions src/api/controller/testController.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ app.use(mongoRootAdminClient);

app.use(
route.delete('/fixtures', async (ctx) => {
await ctx.db.collection('publishedDataset').remove({});
await ctx.db.collection('publishedCharacteristic').remove({});
await ctx.db.collection('field').remove({});
await ctx.db.collection('dataset').remove({});
await ctx.db.collection('subresource').remove({});
await ctx.db.collection('enrichment').remove({});
await ctx.db.collection('publishedDataset').drop();
await ctx.db.collection('publishedCharacteristic').drop();
await ctx.db.collection('field').drop();
await ctx.db.collection('dataset').drop();
await ctx.db.collection('subresource').drop();
await ctx.db.collection('enrichment').drop();
await ctx.rootAdminDb
.collection('tenant')
.remove({ name: { $ne: DEFAULT_TENANT } });
.deleteOne({ name: { $ne: DEFAULT_TENANT } });
ctx.body = { status: 'ok' };
}),
);
Expand Down
2 changes: 1 addition & 1 deletion src/api/models/configTenant.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default async (db) => {
};

collection.delete = async (id) =>
collection.remove({ $or: [{ _id: new ObjectId(id) }, { _id: id }] });
collection.deleteOne({ $or: [{ _id: new ObjectId(id) }, { _id: id }] });

collection.update = async (id, data) => {
const objectId = new ObjectId(id);
Expand Down
4 changes: 2 additions & 2 deletions src/api/models/dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export default (db) => {
};

collection.removeAttribute = async (attribute) =>
collection.update({}, { $unset: { [attribute]: 1 } }, { multi: true });
collection.updateOne({}, { $unset: { [attribute]: 1 } }, { multi: true });

collection.findBy = async (fieldName, value) => {
if (!(await collection.ensureIsUnique(fieldName))) {
Expand Down Expand Up @@ -201,7 +201,7 @@ export default (db) => {
};

collection.deleteOne = async (id) =>
collection.remove({ _id: new ObjectID(id) });
collection.deleteOne({ _id: new ObjectID(id) });

return collection;
};
2 changes: 1 addition & 1 deletion src/api/models/enrichment.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default async (db) => {
};

collection.delete = async (id) =>
collection.remove({ $or: [{ _id: new ObjectId(id) }, { _id: id }] });
collection.deleteOne({ $or: [{ _id: new ObjectId(id) }, { _id: id }] });

collection.update = async (id, data) => {
const objectId = new ObjectId(id);
Expand Down
8 changes: 4 additions & 4 deletions src/api/models/field.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,10 @@ export default async (db) => {
};

collection.removeById = (id) =>
collection.remove({ _id: new ObjectID(id), name: { $ne: 'uri' } });
collection.deleteOne({ _id: new ObjectID(id), name: { $ne: 'uri' } });

collection.removeBySubresource = (subresourceId) =>
collection.remove({
collection.deleteOne({
$or: [
{ subresourceId: new ObjectID(subresourceId) },
{ subresourceId },
Expand Down Expand Up @@ -261,7 +261,7 @@ export default async (db) => {
}

if (isLogged) {
await collection.update(
await collection.updateOne(
{
name,
contribution: true,
Expand All @@ -278,7 +278,7 @@ export default async (db) => {
return name;
}

await collection.update(
await collection.updateOne(
{
name,
contribution: true,
Expand Down
2 changes: 1 addition & 1 deletion src/api/models/hiddenResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default async (db) => {
collection.deleteByUri = async (uri) => collection.deleteOne({ uri });

collection.delete = async (id) =>
collection.remove({ _id: new ObjectID(id) });
collection.deleteOne({ _id: new ObjectID(id) });

collection.castIds = castIdsFactory(collection);

Expand Down
2 changes: 1 addition & 1 deletion src/api/models/precomputed.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default async (db) => {
// Collection does not exist, no big deal
console.warn(`Failed to drop collection 'pc_${id}'`);
}
return collection.remove({
return collection.deleteOne({
$or: [{ _id: new ObjectId(id) }, { _id: id }],
});
};
Expand Down
10 changes: 5 additions & 5 deletions src/api/models/publishedDataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default async (db) => {
collection.insertBatchIgnoreDuplicate = (documents) =>
Promise.all(
chunk(documents, 1000).map((data) =>
collection.insert(data, { ordered: false }).catch((e) => {
collection.insertOne(data, { ordered: false }).catch((e) => {
if (e.code === 11000 /* duplicate error */) {
return;
}
Expand Down Expand Up @@ -228,7 +228,7 @@ export default async (db) => {
);

collection.hide = async (uri, reason, date = new Date()) => {
await collection.update(
await collection.updateOne(
{ uri },
{
$set: {
Expand All @@ -242,7 +242,7 @@ export default async (db) => {
};

collection.restore = async (uri) =>
collection.update(
collection.updateOne(
{ uri },
{ $unset: { removedAt: true, reason: true } },
);
Expand All @@ -262,7 +262,7 @@ export default async (db) => {
publicationDate,
};

return collection.update(
return collection.updateOne(
{ uri },
{
$addToSet: {
Expand Down Expand Up @@ -312,7 +312,7 @@ export default async (db) => {
return { result: 'noChange' };
}

await collection.update(
await collection.updateOne(
{
uri,
'contributions.fieldName': name,
Expand Down
2 changes: 1 addition & 1 deletion src/api/models/subresource.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default async (db) => {
};

collection.delete = async (id) =>
collection.remove({ _id: new ObjectID(id) });
collection.deleteOne({ _id: new ObjectID(id) });

collection.update = async (id, data) => {
const objectId = new ObjectID(id);
Expand Down
2 changes: 1 addition & 1 deletion src/api/models/tenant.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default async (db) => {
};

collection.delete = async (id) =>
collection.remove({ $or: [{ _id: new ObjectID(id) }, { _id: id }] });
collection.deleteOne({ $or: [{ _id: new ObjectID(id) }, { _id: id }] });

collection.update = async (id, data) => {
const objectId = new ObjectID(id);
Expand Down
4 changes: 2 additions & 2 deletions src/api/models/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export const castIdsFactory = (collection) => async () => {
(acc, item) =>
acc.then(async () => {
await acc;
await collection.remove({ _id: item._id });
await collection.insert({
await collection.removeOne({ _id: item._id });
await collection.insertOne({
...item,
_id: new ObjectID(item._id),
});
Expand Down
2 changes: 1 addition & 1 deletion src/api/services/enrichment/enrichment.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ export const restoreEnrichments = async (ctx) => {
ctx,
enrichment,
);
await ctx.enrichment.update(enrichment._id, enrichmentWithRule);
await ctx.enrichment.updateOne(enrichment._id, enrichmentWithRule);
}
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/api/services/saveParsedStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export const saveParsedStream = async (ctx, parsedStream) => {

return ctx.dataset.count();
} catch (error) {
await ctx.dataset.remove({ lodex_published: { $exists: false } });
await ctx.publishedDataset.remove({
await ctx.dataset.deleteOne({ lodex_published: { $exists: false } });
await ctx.publishedDataset.deleteOne({
lodex_published: { $exists: false },
});

Expand Down
2 changes: 1 addition & 1 deletion src/api/services/updateFacetValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const removeOldValue = (publishedFacet, field) => async (oldValue) => {
};

const addNewValue = (publishedFacet, field) => async (newValue) => {
await publishedFacet.update(
await publishedFacet.updateOne(
{ field, value: newValue },
{ $inc: { count: 1 } },
{ upsert: true },
Expand Down
10 changes: 5 additions & 5 deletions src/common/tests/fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ export async function clear() {
}

await Promise.all([
db.dataset.remove({}),
db.field.remove({}),
db.publishedCharacteristic.remove({}),
db.publishedDataset.remove({}),
db.publishedFacet.remove({}),
db.dataset.drop(),
db.field.drop(),
db.publishedCharacteristic.drop(),
db.publishedDataset.drop(),
db.publishedFacet.drop(),
]);

return db;
Expand Down

0 comments on commit 319ef32

Please sign in to comment.