Skip to content

Instantly share code, notes, and snippets.

View acl0056's full-sized avatar

Adam Lockhart acl0056

  • Dallas, TX USA
View GitHub Profile
// If localStorage is not really required, this will at least provide storage while the app is running.
var storage = typeof window.localStorage !== "unknown" ? window.localStorage : {
getItem: function(key) {
return (this.items || (this.items = {}))[key];
},
setItem: function(key, value) {
(this.items || (this.items = {}))[key] = value;
},
clear: function() {
@acl0056
acl0056 / subdocument-index.js
Created April 22, 2016 15:12
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