Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3280836
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:44:57+00:00 2026-05-17T19:44:57+00:00

I have the following MongoDB object stored in my Mongo database: array ( ‘_id’

  • 0

I have the following MongoDB object stored in my Mongo database:

array (
  '_id' => new MongoId("4cc183de48aa4c7708000000"),
  'vehicleMake' => 'Volkswagen',
  'vehicleModel' => 'Carrier',
  'vehicleNumPassengers' => '7',
  'vehicleReg' => '07-D-748393',
  'coords' => 
  array (
    0 => 
    array (
      'lat' => '53.2594946',
      'lng' => '-6.1760780',
      'timestamp' => '12345678',
    ),
    1 => 
    array (
      'lat' => '53.8994946',
      'lng' => '-6.1460780',
      'timestamp' => '12345678',
    ),
  ),
)

And in java, I can access the fields ‘vehicleMake’, ‘vehicleModel’, ‘vehicleNumPassengers’, ‘vehicleReg’ fine using the following 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????
    //    
}

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.

I’ve tried messing around with BasicDBObject but can’t seem to get anything to work.

Any help greatly appreciated.

Many thanks in advance,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T19:44:57+00:00Added an answer on May 17, 2026 at 7:44 pm

    you have to do:

    BasicDBObject query = new BasicDBObject();
    query.put("array.lat");
    collection.find(query);
    

    or

    do this:

    System.out.println(cursor.next().get("coords").get("lat"));
    

    you will also have to add a BSONObject cast to it.

    EDIT: I Think the first method is incorrect. you also need a value pair to go along.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following mongodb object: { _id: ObjectId(4d0b9c7a8b012fe287547157), messages: { 0: { toUname:
Greetings, I have the following mongodb object: { _id: ObjectId(4d0b9c7a8b012fe287547157), messages: { 0: {
I'm new to Rails development and I'm starting with MongoDB also. I have been
I have a collection of articles in MongoDB that has the following structure: {
I am using django-nonrel and django-mongodb-engine I have a Django model stored on PostgreSQL
I am absolutely totally news to Rails and to MongoDB. I have been following
I have following situation: I have loged user, standard authentication with DB table $authAdapter
I have following string String str = replace :) :) with some other string;
I have following foreach-loop: using System.IO; //... if (Directory.Exists(path)) { foreach(string strFile in Directory.GetFiles(path,
I have following situation. A main table and many other tables linked together with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.