mblarsen / mongoose-hidden

A Mongoose schema plugin for filtering properties you usually do not want to sent client-side like passwords and IDs.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

I am having issue while using mongoose populate

zzzet opened this issue · comments

commented

Hi Michael,
I was using this plugin and while trying to use populate, i get no data of that field and if i disable the plugin i get the data from another collections too with populate

[{
    "username": "nora.lama@gmail.com",
    "group": "admin",
    "scope": "admin",
    "company": {
        "_id": "5613a1c7e1095d8e71ae90da",
        "name": "GOGGLE",
        "code": "GOG",
       },
    "isVerified": true,
    "name": {
        "first": "tej",
        "last": "me"
    },
    "id": "5613a1c7e1095d8e71ae90db"
}]

and while i enable the plugin:

[{
    "username": "nora.lama@gmail.com",
    "group": "admin",
    "scope": "admin",
    "isVerified": true,
    "name": {
        "first": "tej",
        "last": "me"
    },
    "id": "5613a1c7e1095d8e71ae90db"
}]

and my query looks like

User.find({}).populate('company').exec(function(err, users){
console.log(users);
});

Hi @tezlopchan

Please confirm that this test case covers the issue.

I'm creating a company and a user. Then I associate the two. After saving I retrieve the user and populates. The company is there as it should.

But perhaps I've misunderstood the problem. Can I see your Schema definitions and how you associate the two documents?

commented

Well i have the CompanySchema and UserSchema as below:

var CompanySchema = new Schema({
    name: { type: String, trim: true, require: true, unique: true },
    status: { type: Boolean, Default: false},
    code: { type: String, min: 3, max: 3, unique: true }
})
var UserSchema = new Schema({
        username: { type: String, trim: true, require: true, unique: true},
        name: {
            first: { type: String, trim: true, require: true},
            last: { type: String, trim: true, require: true}
        },
        scope: {type: String, enum: ['superadmin', 'admin', 'employee']},
        company: { 
                type: Schema.ObjectId, 
                ref: 'Company'
            },
        isVerified: { type: Boolean, default: false }
    });

That seems identical to the test cases I created. Can you try to test the latest version: 5.1 — I updated dependencies, they were about old.

commented

Thank you I will test it right now

commented

Its working.. thanks for the update 👍 👍