White Noise
White Noise

Reputation: 373

Mongoose SchemaTypes Syntax: Array of ObjectIds

Is this

blog: [{type: Schema.Types.ObjectId, ref: 'BlogEntry'}]

the same as this

blog: {type: [Schema.Types.ObjectId], ref: 'BlogEntry'}

or is the second example incorrect?

Upvotes: 2

Views: 2919

Answers (1)

David Daza
David Daza

Reputation: 155

Both are correct, but they're not the same. In the first one, the key blog is an array of objects. Each object contains two keys: type and ref where type is a single ObjectId and ref is already define. In the second one the key blog is no longer an array but a single object. Now, in this object the key type is an array of ObjectId.

Upvotes: 4

Related Questions