const { id: artistId } = req.params;
const albums = await Album.find({artist: artist._id});
if (!albums?.length) {
return res.status(404).send({error: 'Album or artist not found!'});
}
const albumsIds = albums.map(album => album._id);
const allTracks = await Track.find({ album: { $in: albumsIds } });
if (!allTracks?.length) {
return res.status(404).send({error: 'Tracks not found!'});
}
const tracksIds = allTracks .map(track=> track._id);
await TrackHistory.deleteMany({ track: { $in: tracksIds } });
await Track.deleteMany({ album: { $in: albumsIds } });
await Album.deleteMany({artist: artistId});
await Artist.deleteOne({ _id: artistId});
res.send('Delete successful!');
const validConditions = {
$and: [
{
$or: [
{ 'conditions.age': { $exists: false } },
{ 'conditions.age': 20 },
],
},
{
$or: [
{ 'conditions.name': { $exists: false } },
{ 'conditions.name': 'John' },
],
},
{
$or: [
{ 'conditions.surname': { $exists: false } },
{ 'conditions.surname': 'White' },
],
},
],
};
const result = await Test.find(validConditions);
SELECT * FROM entries WHERE age = 20 OR age IS NULL AND name = 'John' OR name IS NULL AND surname = 'White' OR surname IS NULL