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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:32:34+00:00 2026-06-11T16:32:34+00:00

I have source and destination fields in my mongodb collection named Flight . Both

  • 0

I have source and destination fields in my mongodb collection named Flight. Both the fields are geospatially indexed and written in lat-long format. I am using mongomapper to query it from rails controller.

I want to write a query like following.

Result= Flight.where(:source => {'$near' =>  location_src} , :destination => {'$near' => location_dest} )

where location_src and location_dest are gui inputs in lat-long format.

However, when I try to access the Result by writing Result.first or Result.all, it says that
Mongo::OperationFailure: can't have 2 special fields .

Can anyone suggest me what could be the workaround?

Kind Regards,
Amrish.

  • 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-11T16:32:35+00:00Added an answer on June 11, 2026 at 4:32 pm

    I found a simple workaround which serves my purpose and might be helpful to someone facing the similar scenario.

    Though mongodb does not support geospatial query on multiple fields simultaneously, it still supports geospatial indexing on multiple fields simultaneously. So, we would run query on both the fields one after another as follows.

    • start_place : name of starting place
    • start_place_loc : co-ordinates of the starting location (indexed geospatial field)
    • end_place : name of destination place
    • end_place_loc : co-ordinates of the destination location (indexed geospatial field)

    Following is the example code.

    tmp=Flight.distinct(:start_place,:start_place_loc => {'$near' =>  location_src} )
    
    Result=Flight.where(:start_place_loc => {'$near' =>  location_src} , :start_place => {'$in' => tmp})
    

    Also, one will need to set ‘$maxDistance’ => “value” according to one’s requirement.

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

Sidebar

Related Questions

I have 2 tables Source and Destination that have the same fields. ID and
Both source and destination tables have about 40 columns. No. of rows to be
I have two identical SQL Server tables ( SOURCE and DESTINATION ) with lots
I have an OLE DB Data source and a Flat File Destination in the
I have mambo 4.6.5 on my source site and joomla 1.5 on destination site.
I have an Excel source going into an OLE DB destination. I'm inserting data
I have the following HTML table code: <table> <tr> <th>Time</th> <th>Source</th> <th class=hide-on-phones>Destination</th> <th>Duration</th>
I have two GridViews. One is Source GridView and another one is Destination GridView.
Using SSIS 2008 R2, I have an OLE DB source with around 30 fields.
I am creating a RCP application which takes source and destination from text fields

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.