我的文档里面有一个空数组,我想将数组项追加到现有文档中。我正在使用PyMongo。以下是文档。我想附加到邮件数组中
{
"_id": ObjectId("5d4ab779c24423e46aee7171"),
"name": "John",
"author": NumberLong(12345345890),
"messages": []
}
db.collection.update_one({
"author": id
}, {
"$push": {
"messages": {
"timestamp": timestamp,
"text": text
}
}
})