node-mongo-seeds icon indicating copy to clipboard operation
node-mongo-seeds copied to clipboard

Can we set sequence to seed collections?

Open Vladinho10 opened this issue 5 years ago • 7 comments

For example we have 2 collections medias and campaigns. In CampaignSchema we have medias field medias: [{ type: ObjectId, ref: 'Media' }],

For population medias in campaigns, we need in campaigns.js file set medias documents _ids, but your seed invoke at first campaigns.js, after it medias.js file, so we cant use any media's _id.

Vladinho10 avatar Mar 15 '19 08:03 Vladinho10

So you're asking for a way to specify the order of the files to be seeded?

toymachiner62 avatar Mar 19 '19 02:03 toymachiner62

Yeah, something like that

Vladinho10 avatar Mar 20 '19 05:03 Vladinho10

Can you provide an example of some way you'd anticipate doing this?

toymachiner62 avatar Mar 29 '19 01:03 toymachiner62

for example we can set file name starting with 1., 2., 3., and so on. You should slice file name after dote. In my case I will set 1.media 2.campaign then seed will create media collection, then campaign. So I will able to use media's _id in campaign collection

Vladinho10 avatar Apr 02 '19 08:04 Vladinho10

In this example would you seed media, then manually copy and paste the _id's into campaign and then seed just that file?

toymachiner62 avatar Apr 06 '19 17:04 toymachiner62

Bro suppose that I have 100 medias. So I need to set their all 100 _id manually? I think it's not the dynamic solution of our problem.

Vladinho10 avatar Apr 11 '19 05:04 Vladinho10

That's what i'm trying to get out of you. How exactly you'd expect to use this feature. So far you haven't given me a very concrete example.

toymachiner62 avatar Apr 11 '19 20:04 toymachiner62