@ -50,28 +50,26 @@ module.exports = async (posts, board) => {
return acc ;
return acc ;
} , { postFiles : [ ] , postBacklinks : [ ] , postMongoIds : [ ] } ) ;
} , { postFiles : [ ] , postBacklinks : [ ] , postMongoIds : [ ] } ) ;
//is there a nicer way to do this
const bulkWrites = [ ] ;
const bulkWrites = [ ] ;
for ( let j = 0 ; j < allPosts . length ; j ++ ) {
for ( let j = 0 ; j < allPosts . length ; j ++ ) {
const post = allPosts [ j ] ;
const post = allPosts [ j ] ;
for ( let i = 0 ; i < post . quotes . length ; i ++ ) {
//remove the backlink to this post from any post that it quoted
const quote = post . quotes [ i ] ;
bulkWrites . push ( {
//remove the backlink to this post from any post that it quoted
'updateMany' : {
bulkWrites . push ( {
'filter' : {
'updateOne' : {
'_id' : {
'filter' : {
'$in' : post . quotes . map ( q => q . _id )
'_id' : quote . _id
}
} ,
} ,
'update' : {
'update' : {
'$pull' : {
'$pull' : {
'backlinks' : {
'backlinks' : {
'postId' : post . postId
'postId' : post . postId
}
}
}
}
}
}
}
} ) ;
}
}
} ) ;
}
}
if ( bulkWrites . length > 0 ) {
if ( bulkWrites . length > 0 ) {
await Posts . db . bulkWrite ( bulkWrites ) ;
await Posts . db . bulkWrite ( bulkWrites ) ;