0

I want to join two tables in mongoDB. I have table-1) location

   "_id" : ObjectId("5c0f5d16e32f1fe49e648ac8"),
    "device_time" : "2018-11-30 10:48:44",
    "l_created_date" : "2018-11-30 10:49:18",
    "ignition_status" : "1",
    "longitude" : "80.175472",
    "no_of_satellites" : 9,
    "latitude" : "12.938165",
    "speed" : "12",
    "box_status" : "0"

table-2) latlong

    "_id" : ObjectId("5c11083daeb33b4d1175fbd2"),
    "full_address" : "CH023 , Guindy Nagar , 6th St , Sriram Nagar , Ramapuram ,  Mumbai , MHA , 560254 , India",
    "latitude" : "14.0275279",
    "longitude" : "81.1821585",
    "__v" : 0

I want to join both the tables based on latitude so that after aggregation i can get left table record along with match condition.

Could anybody help me regarding that.

Ashh
  • 44,693
  • 14
  • 105
  • 132
user2285878
  • 3
  • 1
  • 3

1 Answers1

1

$lookup aggregation pipeline is used to join two Mongo collection. Using $lookup you can get your required result. Check this query once:

db.location.aggregate([
  {
    $lookup: {
      from: "latlong",
      localField: "latitude",
      foreignField: "latitude",
      as: "latitude_data"
    }
  }
])

Also, you can continue with the required fields by adding the $project stage.