MongoDB
 sql >> Teknologi Basis Data >  >> NoSQL >> MongoDB

Mongodb $lookup di data musim semi mongo

Menggabungkan Dua Koleksi dengan Spring Data MongoDB

Kelas Karyawan

class Employee {
    private String _id;
    private String name;
    private String dept_id;
}

Kelas Jurusan

class Department {
    private String _id;
    private String dept_name;
}

Kelas Hasil Karyawan

public class EmpDeptResult {

    private String _id;
    private String name;
    private List<Object> departments;
}

Kelas Layanan Karyawan

public class EmployeeService {

    @Autowired
    private MongoTemplate mongoTemplate;

    private Logger LOGGER = LoggerFactory.getLogger(EmployeeService.class);

    public void lookupOperation(){
    LookupOperation lookupOperation = LookupOperation.newLookup()
                        .from("Department")
                        .localField("dept_id")
                        .foreignField("_id")
                        .as("departments");

    Aggregation aggregation = Aggregation.newAggregation(Aggregation.match(Criteria.where("_id").is("1")) , lookupOperation);
        List<EmpDeptResult> results = mongoTemplate.aggregate(aggregation, "Employee", EmpDeptResult.class).getMappedResults();
        LOGGER.info("Obj Size " +results.size());
    }
}


  1. Redis
  2.   
  3. MongoDB
  4.   
  5. Memcached
  6.   
  7. HBase
  8.   
  9. CouchDB
  1. Predikat Linq Dinamis memunculkan kesalahan Filter yang Tidak Didukung dengan Driver C# MongoDB

  2. Bagaimana cara kerja pencarian $teks MongoDB?

  3. OData Jaydata - permintaan pembaruan odata mengembalikan kesalahan 404 (SAPUI5, node)

  4. Eksekusi pengurangan peta gagal dengan pymongo tetapi berhasil di mongo shell

  5. Peta PHP MongoDB mengurangi kegagalan pernyataan db