mongodb-js / mongoose-autopopulate

Always populate() certain fields in your mongoose schemas
Apache License 2.0
221 stars 36 forks source link

does it support populating type String ? #49

Closed firstpersoncode closed 5 years ago

firstpersoncode commented 5 years ago

I read the document but couldn't find any guide where we use { type: String }

I wonder if we actually could use it ?

firstpersoncode commented 5 years ago

alright, my app crashed because I tried autopopulate field with type String..

{
        "message": "Cast to ObjectId failed for value \"Page-wMnot7nkUXFsujTtkSrtO19p\" at path \"_id\" for model \"Page\"",
        "name": "CastError",
        "stringValue": "\"Page-wMnot7nkUXFsujTtkSrtO19p\"",
        "kind": "ObjectId",
        "value": "Page-wMnot7nkUXFsujTtkSrtO19p",
        "path": "_id"
},
vkarpov15 commented 5 years ago

You can set autopopulate on a string, but remember that both the local field and foreign field must be strings. In your case, you're setting autopopulate on a string, but the foreign models IDs are ObjectIds, not string.