Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I search across collections in MongoDB?

I am inserting my data into MongoDB and had 240 such files. Instead of inserting everything into one big collection, I was thinking of inserting the files as a collection by themselves. Is this a good idea if I do a lot of queries on a commonly indexed column?

If so, how can I initiate a query to query all the collections in my database?

like image 968
Legend Avatar asked Oct 02 '10 18:10

Legend


People also ask

How do I search multiple collections in MongoDB?

Steps for Joining Two Collections in MongoDB For performing MongoDB Join two collections, you must use the $lookup operator. It is defined as a stage that executes a left outer join with another collection and aids in filtering data from joined documents.

Does MongoDB support query join between collections?

Does MongoDB supports query joins between collections ? No MongoDB doesnot supports query joins between collections.

Can a MongoDB have multiple collections?

Each MongoDB collection can have multiple documents. A document is equilant to row in a table in RDBMS. To create a collection, use the db. createCollection() command.

Which method is used to search data from MongoDB collection?

Find() Method. In MongoDB, find() method is used to select documents in a collection and return a cursor to the selected documents.


2 Answers

Using an application server such as Solr can help you achieve what you want, also with the addition of fuzzy matching, synonyms, phonetic matching, misspellings, etc.

Solor is built on top of Lucene. It's docs are here:

http://lucene.apache.org/solr/

The learning curve is a little bit steep, but you can get pretty good searchability using much of its defaults, leaving you to build a schema and index your data to get started.

like image 182
Chris Adragna Avatar answered Sep 20 '22 18:09

Chris Adragna


I think the answer you're looking for is really here on your other question: Is there any multicore exploiting NoSQL system?

There is no way to query across all collections in Mongo. It wouldn't make a lot of sense to do so. MongoDB's strength is focused on tactically denormalizing data into collections. Providing operations to query across all collections run exactly counter to the concept of tactical denormalization.

In theory, you could just run 240 queries. But more practically you'll probably end up "partitioning" your data so that you only need to query some of the collections. At this point you end up back at the link I provided above, which suggests that sharding your data is probably the answer here.

like image 38
Gates VP Avatar answered Sep 22 '22 18:09

Gates VP