How do I use fields other than primary key _id for association queries?

  mongodb, question

Now there is an article post’s model that uses cateId to associate Category. However, cateId is not _id. Causing an error in acquisition.
Can I only use _id to correlate? How do I use the non _id under Category to associate?

var PostSchema = new mongoose.Schema({
 author: { type: mongoose.Schema.Types.ObjectId},
 title: String,
 content: String,
 imgUrl: String,
 pv: { type:Number, default:0},
 like: { type:Number, default:0},
 keep:  { type:Number, default:0},
 comments: { type:Number, default:0},
 cateId: { type:Number, ref:'Category'},
 type:  Number,
 create_date: { type: Date, default: }
 versionKey: false
 var Post = mongoose.model('Post', PostSchema)

1, the populate of 1,Mongoose can only be on _id;

2, therefore, you can only write your own code for association here, first query one collection, then query another collection, and you have your own association.

For reference.

Love MongoDB! Have fun!

The 2017MongoDB Chinese Community Beijing User Group Conference is approaching, June 3, 2017, 13: 00-18: 00

Sign up!Please poke left!