diff --git a/src/api/controller/api/publishFacets.js b/src/api/controller/api/publishFacets.js index 23bc09840..205cff221 100644 --- a/src/api/controller/api/publishFacets.js +++ b/src/api/controller/api/publishFacets.js @@ -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( diff --git a/src/api/controller/testController.js b/src/api/controller/testController.js index 316334f48..2653791de 100644 --- a/src/api/controller/testController.js +++ b/src/api/controller/testController.js @@ -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' }; }), ); diff --git a/src/api/models/configTenant.js b/src/api/models/configTenant.js index d4a13d4a5..dfc9ce13f 100644 --- a/src/api/models/configTenant.js +++ b/src/api/models/configTenant.js @@ -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); diff --git a/src/api/models/dataset.js b/src/api/models/dataset.js index 37ec407a4..e6ff38ca3 100644 --- a/src/api/models/dataset.js +++ b/src/api/models/dataset.js @@ -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))) { @@ -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; }; diff --git a/src/api/models/enrichment.js b/src/api/models/enrichment.js index 6c3492054..c0d8067aa 100644 --- a/src/api/models/enrichment.js +++ b/src/api/models/enrichment.js @@ -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); diff --git a/src/api/models/field.js b/src/api/models/field.js index 1baa8d796..c73935645 100644 --- a/src/api/models/field.js +++ b/src/api/models/field.js @@ -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 }, @@ -261,7 +261,7 @@ export default async (db) => { } if (isLogged) { - await collection.update( + await collection.updateOne( { name, contribution: true, @@ -278,7 +278,7 @@ export default async (db) => { return name; } - await collection.update( + await collection.updateOne( { name, contribution: true, diff --git a/src/api/models/hiddenResource.js b/src/api/models/hiddenResource.js index 32452a592..7b973df58 100644 --- a/src/api/models/hiddenResource.js +++ b/src/api/models/hiddenResource.js @@ -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); diff --git a/src/api/models/precomputed.js b/src/api/models/precomputed.js index 1ed75a075..cd1e3b9bb 100644 --- a/src/api/models/precomputed.js +++ b/src/api/models/precomputed.js @@ -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 }], }); }; diff --git a/src/api/models/publishedDataset.js b/src/api/models/publishedDataset.js index 2ea88347b..8871cce74 100644 --- a/src/api/models/publishedDataset.js +++ b/src/api/models/publishedDataset.js @@ -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; } @@ -228,7 +228,7 @@ export default async (db) => { ); collection.hide = async (uri, reason, date = new Date()) => { - await collection.update( + await collection.updateOne( { uri }, { $set: { @@ -242,7 +242,7 @@ export default async (db) => { }; collection.restore = async (uri) => - collection.update( + collection.updateOne( { uri }, { $unset: { removedAt: true, reason: true } }, ); @@ -262,7 +262,7 @@ export default async (db) => { publicationDate, }; - return collection.update( + return collection.updateOne( { uri }, { $addToSet: { @@ -312,7 +312,7 @@ export default async (db) => { return { result: 'noChange' }; } - await collection.update( + await collection.updateOne( { uri, 'contributions.fieldName': name, diff --git a/src/api/models/subresource.js b/src/api/models/subresource.js index 7e5921f9c..525451778 100644 --- a/src/api/models/subresource.js +++ b/src/api/models/subresource.js @@ -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); diff --git a/src/api/models/tenant.js b/src/api/models/tenant.js index ae0f9523c..b5f990c16 100644 --- a/src/api/models/tenant.js +++ b/src/api/models/tenant.js @@ -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); diff --git a/src/api/models/utils.js b/src/api/models/utils.js index 2bfc1947c..52b3672ec 100644 --- a/src/api/models/utils.js +++ b/src/api/models/utils.js @@ -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), }); diff --git a/src/api/services/enrichment/enrichment.js b/src/api/services/enrichment/enrichment.js index 083304aaf..bb70cfc5a 100644 --- a/src/api/services/enrichment/enrichment.js +++ b/src/api/services/enrichment/enrichment.js @@ -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); } } }; diff --git a/src/api/services/saveParsedStream.js b/src/api/services/saveParsedStream.js index 0ae0132f4..6ff99b992 100644 --- a/src/api/services/saveParsedStream.js +++ b/src/api/services/saveParsedStream.js @@ -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 }, }); diff --git a/src/api/services/updateFacetValue.js b/src/api/services/updateFacetValue.js index 0675c91ca..cc4eef1fc 100644 --- a/src/api/services/updateFacetValue.js +++ b/src/api/services/updateFacetValue.js @@ -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 }, diff --git a/src/common/tests/fixtures.js b/src/common/tests/fixtures.js index 3f253b159..b7185a502 100644 --- a/src/common/tests/fixtures.js +++ b/src/common/tests/fixtures.js @@ -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;