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

  • Home
  • SEARCH
  • 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 8909763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:30:54+00:00 2026-06-15T03:30:54+00:00

I would like to query multiple collections in mongodb, I have some data like

  • 0

I would like to query multiple collections in mongodb, I have some data like this

Collection stops {
    { stop_id : 1, stop_name: 'a'},
    { stop_id : 2, stop_name: 'b'}, ...

Collection stop_time {
    { stop_id : 1, trip_id: 40},
    { stop_id : 2, trip_id: 41}, ...

Collection trips {
    { trip_id : 40, route_id: 400},
    { trip_id : 41, route_id: 401}, ...

Collection route {
    { route_id : 400, route_name: 'foo'},
    { route_id : 401, route_name: 'bar'}, ...

And for each stop_name, I would like to know the route_name that match with it… (I didn’t chose he data-structure by the way, that’s GTFS format…)

Is there a way to easily do a queries that respond to my problem?

Thanks

  • 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-15T03:30:56+00:00Added an answer on June 15, 2026 at 3:30 am

    Such approach is not good for mongodb.You should create one collection that contains all data, and make only one query.

    This is very important because:

    1. There is no transactions
    2. There is no joins
    3. There are only atomic operations on one document
    4. You will be not able to use aggregation framework

    If it is inpossible to migrate to one collection schema then probably you should do as below:

        var _ = require("underscore")._;
        function get_all(cb) {
            stops.find({}, function(err, stps, cb) {
    
                stop_time.find({}, function(err, stptime) {
    
                    var all = _.map(stps, function(e) {
                        e.trip_id = stptime[e.stop_id].trip_id;
                        return e;
                    });
    
                    trips.find({}, function(err, trips) {
    
                        all = _.map(all, function(e) {
                            e.route_id = trips[e.trip_id].route_id;
                            return e;
                        });
    
                        route.find({}, function(err, routes) {
    
                            all = _.map(all, function(e) {
                                e.route_name = routes[e.route_id].route_name;
                                return e;
                            });
    
                            cb(all)
                        });
                    });
    
                });
            });
        }
    

    Be carefully, if there is a large amount of data in DB then you probably should use Cursors. http://mongoosejs.com/docs/api.html#querystream_QueryStream

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

Sidebar

Related Questions

I have two different tables, lead and click. I would like to query MySQL
I have a query where I use a sub query, and I would like
I would like to query multiple fields using the same regular expression for both.
I would like to query multiple tables from SQL Server 2005 and create a
I have a set of data that shows users, collections of fruit they like,
So I have a boost::multi_index_container with multiple non-unique indexes. I would like to find
I would like to query public posts from multiple Pages. My FQL query looks
I would like to do a LIKE query in persistent, I'm using sqlite. The
I would like to query an XDocument object for a given path, (e.g. /path/to/element/I/want)
I would like to do a query like next: SELECT table_name, column_name, data_type, is_nullable,

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.