Database referenc Using java code

13 views
Skip to first unread message

mohit sharma

unread,
Jul 25, 2016, 7:11:35 AM7/25/16
to mongodb-user
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?

Ross Lawley

unread,
Jul 26, 2016, 5:53:02 AM7/26/16
to mongod...@googlegroups.com
Hi Mohit,

Please see the Mongo Java Driver quick tour documentation, it covers your scenarios.

You can even use the Document.parse(json) method to create the documents from extended json, if that is preferable to using the append methods.

All the best,

Ross

--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/15bea4f0-fbc5-4d52-91f0-3e6d500891a0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--


{ name     : "Ross Lawley",
  title    : "Senior Software Engineer",
  location : "London, UK",
  twitter  : ["@RossC0", "@MongoDB"],
  facebook :"MongoDB"}

Reply all
Reply to author
Forward
0 new messages