Created
April 22, 2016 15:12
-
-
Save acl0056/306a7924925ffc99a0c02e84fa0dbf27 to your computer and use it in GitHub Desktop.
Mongoose index on subdocument _id
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
I couldn't find an example of this anywhere, so here it is. | |
This example uses Mongoose 4, where objects in an array are given their own schema automatically. | |
*/ | |
var mongoose = require("mongoose"); | |
var mySchema = mongoose.Schema({ | |
name: String, | |
things: [{ | |
_id: {auto: true, type: mongoose.Schema.ObjectId, index: true}, | |
name: String | |
}] | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment