diff --git a/packages/bitcore-node/src/models/coin.ts b/packages/bitcore-node/src/models/coin.ts index 288e0831dc7..52cd63ee751 100644 --- a/packages/bitcore-node/src/models/coin.ts +++ b/packages/bitcore-node/src/models/coin.ts @@ -49,6 +49,10 @@ class Coin extends BaseModel { onConnect() { this.collection.createIndex({ mintTxid: 1, mintIndex: 1 }); + this.collection.createIndex( + { mintTxid: 1, mintIndex: 1, chain: 1, network: 1 }, + { partialFilterExpression: { spentHeight: { $lt: 0 } } } + ); this.collection.createIndex( { address: 1, chain: 1, network: 1 }, { partialFilterExpression: { spentHeight: { $lt: 0 } } } diff --git a/packages/bitcore-node/src/models/transaction.ts b/packages/bitcore-node/src/models/transaction.ts index 4627b731a52..d8480811433 100644 --- a/packages/bitcore-node/src/models/transaction.ts +++ b/packages/bitcore-node/src/models/transaction.ts @@ -210,29 +210,20 @@ export class Transaction extends BaseModel { } mintOps.push({ - updateOne: { - filter: { + insertOne: { + document: { + chain, + network, mintTxid: txid, mintIndex: index, - spentHeight: { $lt: SpentHeightIndicators.minimum }, - chain, - network - }, - update: { - $set: { - chain, - network, - mintHeight: height, - coinbase: isCoinbase, - value: output.satoshis, - address, - script: scriptBuffer, - spentHeight: SpentHeightIndicators.unspent, - wallets: [] - } - }, - upsert: true, - forceServerObjectId: true + mintHeight: height, + address, + coinbase: isCoinbase, + value: output.satoshis, + script: scriptBuffer, + spentHeight: SpentHeightIndicators.unspent, + wallets: [] + } } }); }