这是我第一次使用MongoDB和Spring-data-mongo。
有Company
个对象
@Document
public class Company {
@Id
private String id;
private String name;
private String registrationNumber;
private List<Vehicle> vehicles;
}
public class Vehicle {
private String vehicleOwner;
@Indexed(unique = true)
private String plateNumber;
private Double speedLimit;
private GeoJsonPoint currentLocation;
}
我想更新具有给定currentLocation
plateNumber
字段
显然,我被困在这里
mongoTemplate.find(Query.query(Criteria.where("vehicles"))), how to go to `plateNumber` field? And how to update `currentLocation` field for that particular matching `Vehicle` for the `Company`
答案 0 :(得分:1)
这应该有效,将查询框架化以获取所需文档,然后创建Update对象并填充值,如下所示,
currentLocation
您可以尝试更新var _hero = [{
nick: "Mike",
lvl: 500,
x: 10,
y: 10
}, {
nick: "Mike",
lvl: 500,
x: 15,
y: 15
}]
let main = () => {
_hero.forEach(function(_hero) {
if (_hero.nick == "Mike") {
console.log(_hero);
}
});
};
main();
。