Scheme of nested objects in mongoose

Suppose I have such a circuit

var Language = new Schema({ name: { type: String, unique: true, required: true }, pos: [{ name: String, attributes: [{ name: String }] }] }); 

Will each element in pos and attributes have _id ? If I add a unique index to the name field in the pos array, will uniqueness only apply to this array or will it be unique to all entries?

+4
source share
2 answers

No, inline documents, such as pos and attributes , which do not have their own schema, do not have the _id property.

If you add a unique index to the name field in the pos array, uniqueness will be applied in the collection, but not in the array of one document. See this post .

+3
source

In Mongoose 4, pos and attributes will get their own schema. You can prevent them from receiving _id attributes as follows:

 // ... attributes: [{ name: String, _id: false }] // ... 
+1
source

All Articles