Created
November 8, 2011 17:22
-
-
Save wavded/1348429 to your computer and use it in GitHub Desktop.
Populate a users contacts - works in 2.3.9 but not in 2.3.10
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
#!/usr/bin/env coffee | |
global.mongoose = require 'mongoose' | |
mongoose.connect 'mongodb://localhost/test' | |
Schema = mongoose.Schema | |
User = new Schema | |
userId : { type: String, index: true, required: true } | |
contacts : [ { type: Schema.ObjectId, ref: 'User' } ] | |
User = mongoose.model('User', User) | |
User.remove {}, (err) -> console.log(err) if err | |
console.log "- cleaning out existing users" | |
contacts = [] | |
userIds = [ 'A', 'B', 'C', 'D' ] | |
numRoles = userIds.length | |
userIds.forEach (userId,index) -> | |
User.create { userId: userId }, (err, user) -> | |
if err then console.log err | |
console.log "+ creating user: #{user.userId}" | |
contacts.push(user) unless user.userId is 'A' | |
if --numRoles <= 0 | |
console.log "+ about to update contacts", contacts | |
User.update {userId: 'A'}, { contacts: contacts }, (err) -> # NEVER GETS PAST HERE IN 2.3.10 | |
if err then console.log err | |
console.log "+ updating testarc user to include contacts" | |
process.exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment