Skip to content

Instantly share code, notes, and snippets.

@kevindente
Created October 4, 2012 20:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kevindente/3836058 to your computer and use it in GitHub Desktop.
Save kevindente/3836058 to your computer and use it in GitHub Desktop.
Repro for mongoose issue 1127
var vm = require("vm");
var fs = require("fs");
var path = require("path");
var schemaDecl = fs.readFileSync("schema.js", "utf8");
var mongoose = require("mongoose");
mongoose.connect("localhost", "mongoosetest");
var fileName = path.resolve("schema.js");
var script = vm.createScript(schemaDecl, fileName);
script.runInNewContext({require: require, __filename: fileName});
var model = mongoose.model("AThing");
model.on("index", function(err) {
if (err) console.log(err);
mongoose.disconnect(function() {
});
});
var mongoose = require("mongoose");
var Schema = mongoose.Schema;
var AThingSchema = new Schema({
name: String,
owner: String
}, {autoIndex: true});
AThingSchema.index({name: 1, owner: 1});
mongoose.model("AThing", AThingSchema);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment