I have this schema:
{
"_id" : UUID("f61dacb9-7687-40ea-8c23-b1d7364a95f8"),
"Lat" : "39.74719833333334",
"Lng" : "57.2768",
"CreationDateTime" : ISODate("2017-11-11T08:06:42.729Z"),
"DeviceId" : "89984320000897548912",
"UserId" : UUID("7bc16d9a-9ac4-47af-bc28-adad1622a054"),
"UserName" : "admin",
},...
As you can see i have this fields: Lat and Lng.Now i have decided these fields combine together as a array filed like below :
{
"_id" : UUID("f61dacb9-7687-40ea-8c23-b1d7364a95f8"),
"Lat" : "39.74719833333334",
"Lng" : "57.2768",
"CreationDateTime" : ISODate("2017-11-11T08:06:42.729Z"),
"DeviceId" : "89984320000897548912",
"UserId" : UUID("7bc16d9a-9ac4-47af-bc28-adad1622a054"),
"UserName" : "admin",
"Point" : [
57.2768,
39.74719833333334
] ,
},....
For this purpose i wrote this query:
db.Locations.find().forEach(function(data){
up(data["_id"],data["Lng"], data["Lat"]);
});
var up = function (id,lng,lat){
db.Locations.updateOne(
{_id : id},
{ $addToSet: {Point: [ lng, lat ] } }
);
}
I have used addToSet for this query, But it does not have right answer.In my query just first field is updated like this:
{...
"Point" : [
[
UUID("13fe657e-6f39-4396-a6d1-dc70ddf38201"),
"49.996898333333334"
],
[
UUID("99aa3773-a444-48cb-80ae-958181633fd9"),
"49.998398333333334"
],...
}
It does not my thing that i want??Where is my mistake? First i make a query and then i have updated document by document!!!! Thank you for helping...