现在我有一些像
这样的数据{
"_id" : ObjectId("5a6fe7518fd89a4d33983ca0"),
"id" : "475753578774925312",
"inTime" : ISODate("2018-01-30T03:32:32.000Z")
}
{
"_id" : ObjectId("5a6fe7558fd89a4d33983ca3"),
"id" : "475753578774925312",
"inTime" : ISODate("2018-01-30T03:32:36.000Z")
}
{
"_id" : ObjectId("5a6fe7598fd89a4d33983ca5"),
"id" : "475753578774925312",
"inTime" : ISODate("2018-01-30T03:32:40.000Z")
}
{
"_id" : ObjectId("5a6fe75d8fd89a4d33983ca8"),
"id" : "475753578774925312",
"inTime" : ISODate("2018-01-30T03:32:44.000Z")
}
并且我想在列不存在时更新最新的intime数据设置新的列名称outtime,如果新列已经存在,我希望此更新更改为新的插入,我该怎么办? / p>
首次更新:
{
"_id" : ObjectId("5a6fe7518fd89a4d33983ca0"),
"id" : "475753578774925312",
"inTime" : ISODate("2018-01-30T03:32:32.000Z")
}
{
"_id" : ObjectId("5a6fe7558fd89a4d33983ca3"),
"id" : "475753578774925312",
"inTime" : ISODate("2018-01-30T03:32:36.000Z")
}
{
"_id" : ObjectId("5a6fe7598fd89a4d33983ca5"),
"id" : "475753578774925312",
"inTime" : ISODate("2018-01-30T03:32:40.000Z")
}
{
"_id" : ObjectId("5a6fe75d8fd89a4d33983ca8"),
"id" : "475753578774925312",
"outTime" : ISODate("2018-01-30T03:32:44.000Z"),
"inTime" : ISODate("2018-01-30T03:32:44.000Z")
}
第二次更新:
{
"_id" : ObjectId("5a6fe7518fd89a4d33983ca0"),
"id" : "475753578774925312",
"inTime" : ISODate("2018-01-30T03:32:32.000Z")
}
{
"_id" : ObjectId("5a6fe7558fd89a4d33983ca3"),
"id" : "475753578774925312",
"inTime" : ISODate("2018-01-30T03:32:36.000Z")
}
{
"_id" : ObjectId("5a6fe7598fd89a4d33983ca5"),
"id" : "475753578774925312",
"inTime" : ISODate("2018-01-30T03:32:40.000Z")
}
{
"_id" : ObjectId("5a6fe75d8fd89a4d33983ca8"),
"id" : "475753578774925312",
"outTime" : ISODate("2018-01-30T03:32:44.000Z"),
"inTime" : ISODate("2018-01-30T03:32:44.000Z")
}
{
"_id" : ObjectId("5a6fe75d8fd89a4d33983ca8"),
"id" : "475753578774925312",
"outTime" : ISODate("2018-01-30T03:32:44.000Z")
}
如果这些操作存在并发,我该如何避免重复更新
答案 0 :(得分:0)