mblarsen / mongoose-hidden

A Mongoose schema plugin for filtering properties you usually do not want to sent client-side like passwords and IDs.
MIT License
89 stars 19 forks source link

I am having issue while using mongoose populate #1

Closed zzzet closed 9 years ago

zzzet commented 9 years ago

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);
});
mblarsen commented 9 years ago

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?

zzzet commented 9 years ago

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 }
    });
mblarsen commented 9 years ago

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.

zzzet commented 9 years ago

Thank you I will test it right now

zzzet commented 9 years ago

Its working.. thanks for the update :+1: :+1: