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 8359147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:03:12+00:00 2026-06-09T11:03:12+00:00

I have created a collection in DB and updated with proper indexing to retrieve

  • 0

I have created a collection in DB and updated with proper indexing to retrieve it back. Im getting with the folloging

Example:

db.car.save({ "name":"Toyota car", "affiliation":"Toyota", "loc":{"lon":55.93939251390387,"lat":-113.999}})

db.car.find({"loc" : {"$within" : {"$center" : [[50.93939251390,-114],5]}}})

I have 100K + records in Database when I search the above query returns 20K records.

Actually this has some duplicate values in the “name” column. How can I get the distinct value of “name”.

  • 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-06-09T11:03:14+00:00Added an answer on June 9, 2026 at 11:03 am

    You can’t get the results you need using a query in MongoDB 2.0.x, so will need to manipulate the results in your application code.

    If you are only after names you can limit the fields in the output:

    db.car.find(
        {"loc" : {"$within" : {"$center" : [[50.93939251390,-114],5]}}},
        {"_id": 0, "name": 1}
    )
    

    If you want to find distinct names you could do something like:

    // Save cars we've seen
    > var cars_seen = {}
    
    // The unique list we actually want
    > var cars = []
    
    // Find closest cars to given geo point
    > db.car.find(
        {"loc" : {"$within" : {"$center" : [[50.93939251390,-114],5]}}},
        {"_id": 0, "name": 1}
    ).forEach(
        function(doc) {
            // Add names we haven't seen yet
            if (!cars_seen[doc.name]) {
                cars_seen[doc.name] = 1;
                cars.push(doc.name);
            }
        }
    )
    
    > cars
    [ "Skoda", "Benz", "Skoda SUV" ]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a site collection inside a web application with user A as
I have created a custom collection class that I am trying to bind to
I have a collection of .html files created in the mid-90s, which include a
I have a collection in MongoDB with 20 million documents and an index created
I have a Mongodb collection and I have created a Python class for documents
Suppose I create collection like Collection<IMyType> coll; Then I have many implelentations of IMyTypem
I have the following code: // // POST: /PlayRoundHole/Create [AcceptVerbs(HttpVerbs.Post)] public ActionResult Create(FormCollection collection)
I have to enumerate through the members of a collection and create an array
We have a large internal data collection website. I don't have time to create
We have installed TFS 2010 RC. By default it creates a project collection called

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.