I am currently working on nestjs and have two collections, one for orders and the other for payments. My goal is to retrieve a single entry from the orders collection and save that same entry into the payments collection.
Below is the code for the services:
async order(name){
const list = this.usersmodel.find({name: name}).exec()
//return list
try {
if(list) {
const x = this.usersmodel.aggregate([
{ $out: "payment" }
])
return "data saved in payment collection"
}
}
catch(error) {
return(error.message)
}
}
Below is the code for the controller:
@Get('orderdata')
async orderdata(@Body('name') name) {
return this.usersService.order(name)
}
Despite using this code, I did not achieve the desired output nor did I encounter any errors. When testing the API in Postman, I received the message "data saved in payment collection" but the entries were not actually being saved in my payment collection.