These are chat archives for Automattic/mongoose

15th
Jan 2019
Mathias_D
@D19cannon
Jan 15 12:18

Guys! trying to add a new bid in my db. This worked just fine before, but for some reason it doesn't any more.... Checked the data that I have been sending 1.000.000 times, nothing has been changed before it crashed...

What I am doing is as follow:

` ProductBids.updateOne(
{ "pid": productbids.pid },
{ "$set": { "auction_ends" : productbids.auction_ends } },
{ "$addToSet": { "bids": productbids.bids } },
)

   productbids.save()
  .then(productbid => {
    res.json('[ENDPOINT] Updated new product with new bid succesfully');
  })

`

The result that I get is:
[
{
"_id": "5c3dce9f31d2987ed8d2d6fb",
"pid": "4419",
"auction_ends": "1548079800",
"bids": [
{
"_id": "5c3dce9f31d2987ed8d2d6fc",
"uid": "10",
"bid_amount": 30,
"timestamp": "1547554463284",
"auction_ends": "1548079800"
}
],
"v": 0
},
{
"_id": "5c3dce9c31d2987ed8d2d6f9",
"pid": "4419",
"auction_ends": "1548079800",
"bids": [
{
"_id": "5c3dce9c31d2987ed8d2d6fa",
"uid": "10",
"bid_amount": 20,
"timestamp": "1547554460912",
"auction_ends": "1548079800"
}
],
"
v": 0
}
]

And what I had and want is basically update a new bid in the bids: [{bid1}, {bid2}]:

[
{
"_id": "5c3dce9f31d2987ed8d2d6fb",
"pid": "4419",
"auction_ends": "1548079800",
"bids": [
{
"_id": "5c3dce9f31d2987ed8d2d6fc",
"uid": "10",
"bid_amount": 30,
"timestamp": "1547554463284",
"auction_ends": "1548079800"
},
{
"_id": "5c3dce9c31d2987ed8d2d6fa",
"uid": "10",
"bid_amount": 20,
"timestamp": "1547554460912",
"auction_ends": "1548079800"
}
],
"__v": 0
},

Any suggestions??

Mathias_D
@D19cannon
Jan 15 12:23
Sorry for the mess... can't get the back ticks to work correctly
Brenda
@thehme
Jan 15 19:32
Hi all, i am happy to report that I resolved my issue above with discriminators.
Brenda
@thehme
Jan 15 19:39
@D19cannon it's hard to read your post above, but do I see an update of one object and then also a save? If it helps, maybe use a gist?