我有一个如下文件: { "_id": "1.0", files: [ {"name": "file_1", "size": 1024, "create_ts": 1570862776426}, {"name": "file_2", "size": 2048, "create_ts": 1570862778426} ] }我想用“file_x”更新插入“files”: 1 如果“file_x”已经在“files”中,则更新,例如“file_x”是:{"name": "file_2", "size": 4096, "create_ts": 1570862779426}upsert后的文档是:{ "_id": "1.0", files: [ {"name": "file_1", "size": 1024, "create_ts": 1570862776426}, {"name": "file_2", "size": 4096, "create_ts": 1570862779426}} ]}2 如果“file_x”不在“files”中,则插入它,例如“file_x”为:{"name": "file_3", "size": 4096, "create_ts": 1570862779426}upsert 文档后是:{ "_id": "1.0", files: [ {"name": "file_1", "size": 1024, "create_ts": 1570862776426}, {"name": "file_2", "size": 2048, "create_ts": 1570862778426}, {"name": "file_3", "size": 4096, "create_ts": 1570862779426} ]}那么我可以使用一个函数来归档它吗?
2 回答
- 2 回答
- 0 关注
- 130 浏览
添加回答
举报
0/150
提交
取消