import Transaction from '../models/Transaction'
function sendMessage() {
const existingTx = await Transaction.exists({ transactionHash })
if (existingTx) return 'This transaction has already happened'
//the transaction does NOT exist
//create it..
const transactionAttr = {
from,
textMsg,
recipient,
senderNumber,
transactionHash,
createdAt: new Date(),
}
const transactionRecord = new Transaction(transactionAttr)
await transactionRecord.save()
}
and Transaction is just a Mongoose model…
import mongoose from 'mongoose'
const transactionSchema = new mongoose.Schema({
from: {
type: String,
required: true,
},
createdAt: {
type: Date,
required: true,
},
textMsg: {
type: String,
required: true,
},
recipient: {
type: String,
required: true,
},
senderNumber: {
type: String,
required: true,
},
transactionHash: {
type: String,
required: true,
},
})
export default mongoose.model('Transaction', transactionSchema)
I am running this ExpressJS app on Heroku. Using Altas, and whitlelisting all IPs.
Everytime the code gets here…
const existingTx = await Transaction.exists({ transactionHash })
The Transaction is already created. I have no idea why or how this is happening. It is beyond frustrating. I’ve ripped out all the code that saves the documents… and it STILL SAVES EVERYTIME.
const transactionRecord = new Transaction(transactionAttr)
await transactionRecord.save()
Is there some kind of autosaving going on? Or something strange when using with Heroku that this occurs? I am really super frustrated because it makes no sense why this is happening.