My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more

Mapping references when one reference does not exist in other collection

Argjend's photo
Argjend
·Mar 24, 2018

So, I've two schemas where one has a reference to other, the problem is that for the other one I haven't any reference.

var articleSchema = new mongoose.Schema({

title: {type: String, text: true},
    description: {type: String, text: true},
    url: String,
....



var userSchema = new mongoose.Schema({

...

articles: [{
            type: ObjectId,
            ref: 'Article'}],

...

As seen above, in the article scheme there isn't any reference to the User schema while User schema has the array of article ids as a reference.

My question: Is there any way to get those references and by mapping or using any other method, I want to store for each article the User ID ?