0

i am trying to db.collection.find() i want to find document with docId:'sparksLog' and then find inside it 'alerts' then object2 which has a timestamp as highlighted in the image (1602579600000), and then update last field value ( valid: true) to (valid:false)

I am using pymongo, python3.8

{
    "docId": "sparksLog",
    "alerts": [{
        "symbol": "ATOMUSDT",
        "candleDate": {
            "$date": "2020-10-13T03:30:00.000Z"
        },
        "spotDate": {
            "$date": "2020-10-14T22:36:56.795Z"
        },
        "timeStamp": 1602559800000,
        "alertPrice": 5.925,
        "side": "buy",
        "indicatorName": "Q1200",
        "currentPrice": 5.925,
        "changePercent": 0,
        "accuracy": 59,
        "forecast": 7.94,
        "rating": 5.9,
        "valid": true
    }, {
        "symbol": "ATOMUSDT",
        "candleDate": {
            "$date": "2020-10-13T09:00:00.000Z"
        },
        "spotDate": {
            "$date": "2020-10-14T22:36:57.416Z"
        },
        "timeStamp": 1602579600000,
        "alertPrice": 6.055,
        "side": "sell",
        "indicatorName": "Q140",
        "currentPrice": 6.055,
        "changePercent": 0,
        "accuracy": 59,
        "forecast": -3.25,
        "rating": 5.9,
        "valid": true
    }]
}

enter image description here

2
  • Could you please edit your post and add the collection in json format instead of the image? Commented Oct 14, 2020 at 23:44
  • updated now, thanks in advance Commented Oct 14, 2020 at 23:55

1 Answer 1

1
collection.update_one({
  "docId":'sparksLog'},
  {"$set": { 'alerts.$[t].valid':False}},
  array_filters=[{"t.timeStamp": 1602579600000}])
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.