Store and query NxN matrix
0 I am looking for a way to store and query a N x N matrix. The data will no change frequently. The search must be fast. I have to be able to query the distance (and any other data stored as flights, bus, trains, others) from any city to other. Example: From NY to Boston: Distance: 215 mi, Data: No trains. From Boston to NY: Empty. From Washington DC to NY: Distance: 225 mi, Data: - To represent the data I made a matrix I am working with mongoDB as a database. First option: I am thinking in representing any row of the matrix as a document. city: "NY", destinations: [ city:"Boston", distance: "215 mi", data: "no trains", city:"Washington DC", distance: "226 mi", data: "" ] Cons: Some documents have an array near 4000 destination cities. Pros: there are only 4000 documents in the collection. Second Option : Create a document with any connection of cities: Example: from: "NY", to: "Bo