Skip to content

Instantly share code, notes, and snippets.

@acl0056
Created April 22, 2016 15:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acl0056/306a7924925ffc99a0c02e84fa0dbf27 to your computer and use it in GitHub Desktop.
Save acl0056/306a7924925ffc99a0c02e84fa0dbf27 to your computer and use it in GitHub Desktop.
Mongoose index on subdocument _id
/*
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