A document in my MongoDB Collection has two fields which are
[123.45,11.34]
GeoJSON Point format[[12,45],[78,89],[12,54]]
GeoJSON MultiPoint formatAn array newLongLat from Http Request is in this format : newLongLat = [78.486671,17.385044];
multipleLongLat already has array of arrays.
I need to update two fields as :
Document can be filtered by {"productId" : productId}. I am using Mongoose framework with NodeJS. Please mention an efficient way to perform this operation simultaneously? Thanks in advance.
Simple $set
in an aggregation pipeline. You can simply treat the coordinates field as an inner field of an object.
db.collection.update({
"productId": "p1"
},
[
{
$set: {
"lastLongLat": {
type: "Point",
coordinates: [
78.486671,
17.385044
]
},
"multipleLongLat.coordinates": {
"$concatArrays": [
"$multipleLongLat.coordinates",
[
[
78.486671,
17.385044
]
]
]
}
}
}
])