# Query on multiple collections at once with mongodb

**URL:** https://discuss.elastic.co/t/query-on-multiple-collections-at-once-with-mongodb/226571
**Category:** Elasticsearch
**Created:** [April 5, 2020, 1:42pm UTC](https://discuss.elastic.co/t/query-on-multiple-collections-at-once-with-mongodb/226571 "2020-04-05T13:42:35Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![chawki](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chawki/32/65690_2.png) [@chawki](https://discuss.elastic.co/u/chawki)
#### Post date: [April 5, 2020, 1:42pm UTC](https://discuss.elastic.co/t/query-on-multiple-collections-at-once-with-mongodb/226571/1 "2020-04-05T13:42:35Z")

</div>

Can I able to search on multiple mongodb collections with elastic search at once?

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [April 5, 2020, 3:27pm UTC](https://discuss.elastic.co/t/query-on-multiple-collections-at-once-with-mongodb/226571/2 "2020-04-05T15:27:34Z")

</div>

Welcome!

Elasticsearch does not search in databases but in its own indices.  
You can create one index per database, send the data from each database to the right index and search across multiple indices at once.

---

<div class="post-metadata">

### Author: ![chawki](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chawki/32/65690_2.png) [@chawki](https://discuss.elastic.co/u/chawki)
#### Post date: [April 6, 2020, 5:12am UTC](https://discuss.elastic.co/t/query-on-multiple-collections-at-once-with-mongodb/226571/3 "2020-04-06T05:12:39Z")

</div>

thanks for the reply, First of all, I'm new to Elasticsearch and zero-knowledge, I had a problem with my application database and when I have come across the internet I found Elasticsearch able to solve my problem but I don't have any idea how it can, that's why I asked the question here. Ok, I will explain the problem.

My application(buy and sell) have around five to ten categories

> eg: vehicles, real estate, and cloths

I thought of creating separate MongoDB collections for each category because each of the categories contains with different fields

> eg: vehicle[km, body type, brand], cloths[size, color, gender],

This would be very easy to manage and scale. The problem here is searching if a user searches

> eg: parts

the search should query all collections and return appropriate results and another circumstance if the user sorts the ads from newest to the oldest application should sort the latest post ads from all categories(databases) to oldest ads in order.

Please clarify can able to do this with the Elasticsearch after I will make my hands dirty with Elastic search

thanks

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [April 6, 2020, 3:31pm UTC](https://discuss.elastic.co/t/query-on-multiple-collections-at-once-with-mongodb/226571/4 "2020-04-06T15:31:43Z")

</div>

> [@chawki](#):
>
> Please clarify can able to do this with the Elasticsearch

Not sure I understood everything but IMHO yes. As soon as you have JSON documents indexed in elasticsearch you can query easily, compute aggregations, in near real time...

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [May 4, 2020, 3:31pm UTC](https://discuss.elastic.co/t/query-on-multiple-collections-at-once-with-mongodb/226571/5 "2020-05-04T15:31:43Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
