Note that there are some explanatory texts on larger screens.

plurals
  1. POMongoDB and Java Objects
    primarykey
    data
    text
    <p>I have the following MongoDB object stored in my Mongo database:</p> <pre><code>array ( '_id' =&gt; new MongoId("4cc183de48aa4c7708000000"), 'vehicleMake' =&gt; 'Volkswagen', 'vehicleModel' =&gt; 'Carrier', 'vehicleNumPassengers' =&gt; '7', 'vehicleReg' =&gt; '07-D-748393', 'coords' =&gt; array ( 0 =&gt; array ( 'lat' =&gt; '53.2594946', 'lng' =&gt; '-6.1760780', 'timestamp' =&gt; '12345678', ), 1 =&gt; array ( 'lat' =&gt; '53.8994946', 'lng' =&gt; '-6.1460780', 'timestamp' =&gt; '12345678', ), ), ) </code></pre> <p>And in java, I can access the fields 'vehicleMake', 'vehicleModel', 'vehicleNumPassengers', 'vehicleReg' fine using the following code:</p> <pre><code>Mongo mongo=new Mongo(); DB db=mongo.getDB("garage"); DBCollection cllctn=db.getCollection("drivers"); DBCursor allDrivers=cllctn.find(); while(allDrivers.hasNext()){ DBObject driver=allDrivers.next(); String vehicleMake=driver.get("smsVerified").toString(); String vehicleModel=driver.get("vehicleModel").toString(); String vehicleNumPassengers=driver.get("vehicleNumPassengers").toString(); String vehicleReg=driver.get("vehicleReg").toString(); // //How do I access 'lat', 'lon' and 'timestamp' here???? // } </code></pre> <p>My question is: how do I access the 'lat', 'lon' and 'timestamp' values inside the MongoDB array? I'm completely stumped and can't find anything on the mongodb website or on Google.</p> <p>I've tried messing around with BasicDBObject but can't seem to get anything to work.</p> <p>Any help greatly appreciated.</p> <p>Many thanks in advance,</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload