db.Job.insert({"job_Title" : "Website", "job_Location" : "Kolkata", "salary" : "40000", "company" : "ROHIT", "department" : { "$ref": "department", "$id": ObjectId("579302282d180c1b80be65ec"), "$db": "test"}, "status":"Act"})
var job = db.Job.findOne({"company":"LOKI"})
var dep = job.department db[dep.$ref].findOne({"_id":(dep.$id)})
How we write this mongoDB shell query in Java program for insert and find Document?