5

In my code when a process starts the following data are stored in my core_pid table.

db.core_pid.insert({"blog_id": blog["_id"], "proid": str(p.pid), "starttime": datetime.now(pytz.timezone('EST')), "status": "Running", "route":routing})

After the process is completed i updated the value of status using the below code.

db.core_pid.update({"_id": current_id},
                       {"$set": {"status": "Completed"}}) 

Now i want to include a new field endtime in database when process is completed ({"endtime": datetime.now(pytz.timezone('EST'))}).How can i alter the above update code to include this endtime field too.

2 Answers 2

11

Simply, include the "endtime" field in "$set" value

db.core_pid.update({"_id": current_id},
                   {"$set": {
                       "status": "Completed",
                       "endtime": datetime.now(pytz.timezone('EST'))}}) 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks man. I tried this and it didn't worked before. I thought the query was wrong. The Actual problem was with the variable current_id. Now its working..
0

Simply add the other field as an argument to $set:

b.core_pid.update({"_id": current_id},
    {"$set": { 
        "status": "Completed",
        "endtime": datetime.now(pytz.timezone('EST')) 
    }})

And that will just update both of those fields in the document without touching others.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.