# Mapping / Importing / Indexing, MongoDB (Mongoid) embedded 1-n relations

**URL:** <https://discuss.elastic.co/t/mapping-importing-indexing-mongodb-mongoid-embedded-1-n-relations/10422>\
**Category:** Elasticsearch\
**Created:** [January 19, 2013, 9:17pm UTC](https://discuss.elastic.co/t/mapping-importing-indexing-mongodb-mongoid-embedded-1-n-relations/10422 "2013-01-19T21:17:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lgs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lgs/32/44848_2.png) [@lgs](https://discuss.elastic.co/u/lgs)\
**Post date:** [January 19, 2013, 9:17pm UTC](https://discuss.elastic.co/t/mapping-importing-indexing-mongodb-mongoid-embedded-1-n-relations/10422/1 "2013-01-19T21:17:48Z")

</div>

In MongoDB integration tests ( test/models/mongoid\_models.rb[https://github.com/karmi/tire/blob/master/test/models/mongoid\_models.rb](https://github.com/karmi/tire/blob/master/test/models/mongoid_models.rb))are shown some  
referenced 1-n [http://mongoid.org/en/mongoid/docs/relations.html#has\_many](http://mongoid.org/en/mongoid/docs/relations.html#has_many)mongoid relations.

Is that applicable to embedded 1-n[http://mongoid.org/en/mongoid/docs/relations.html#embeds\_many](http://mongoid.org/en/mongoid/docs/relations.html#embeds_many)relations too out of the box, or some more tricks are needed ?

Is that possible to extend test/models/mongoid\_models.rb[https://github.com/karmi/tire/blob/master/test/models/mongoid\_models.rb](https://github.com/karmi/tire/blob/master/test/models/mongoid_models.rb)with embeds\_many  
/ embedded\_in example models ?

I tried doing the following:

class User

include Mongoid::Document

include Tire::Model::Search

include Tire::Model::Callbacks

tire do

```
mapping do

  indexes :nickname

  indexes :watchlists do

    indexes :description

    indexes :html_url

    indexes :tags

  end

end

```

end

def to\_indexed\_json

```
{

  :nickname => nickname,

  :watchlists => watchlists.map { |c| { :_type => 'mongoid_watchlist',

                                        :_id => c.id,

                                        :description => c.description,

                                        :html_url => c.html_url,

                                        :tags => c.tags } }

}.to_json

```

end

field :nickname

embeds\_many :watchlists

end

class Watchlist

include Mongoid::Document

field :description

field :html\_url

field :tags

embedded\_in :user

end

but then, running tire:import, it seems never ending :

RAILS\_ENV=production rake environment tire:import CLASS=User FORCE=true

--

---

<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:** [July 6, 2017, 2:55am UTC](https://discuss.elastic.co/t/mapping-importing-indexing-mongodb-mongoid-embedded-1-n-relations/10422/2 "2017-07-06T02:55:32Z")

</div>


