Skip to content

Instantly share code, notes, and snippets.

View bnoguchi's full-sized avatar

Brian Noguchi bnoguchi

View GitHub Profile
@bnoguchi
bnoguchi / GH-228.js
Created June 9, 2011 07:46
Example of how to correctly do mongoose GH-228
var mongoose = require('mongoose')
, Schema = mongoose.Schema;
var db = mongoose.connect('mongodb://localhost/test');
var TestEmbedSchema = new Schema({
name : { type: String, index: true}
});
var TestEmbed = mongoose.model('TestEmbed', TestEmbedSchema);
@bnoguchi
bnoguchi / GH-246.js
Created June 9, 2011 07:54
Example demonstrating the request in mongoose GH-246 is now supported
var mongoose = require('mongoose')
, Schema = mongoose.Schema ;
var PageSchema = new Schema({
author: {
first_name: String
, last_name: String
}
});
@bnoguchi
bnoguchi / GH-230.1.js
Created June 9, 2011 08:12
How to get mongoose GH-230 examples working without errors
// 'test pushing simple embedded documents into a document'
var mongoose = require('mongoose')
, should = require('should')
, Schema = mongoose.Schema;
mongoose.connect('mongodb://localhost/test');
var EmbeddedSchema = new Schema({
title : String
@bnoguchi
bnoguchi / GH-241.js
Created June 9, 2011 08:20
mongoose GH-241 non-failing example
var mongoose = require('mongoose')
, Schema = mongoose.Schema ;
mongoose.connect('mongodb://localhost/test');
var ContactNameSchema = new Schema({
familyName: String,
givenName: String
});
@bnoguchi
bnoguchi / GH-301.js
Created June 9, 2011 09:09
Example showing that mongoose GH-301 is now irrelevant
var mongoose = require('mongoose')
, Schema = mongoose.Schema
, ObjectId = mongoose.SchemaTypes.ObjectId
, should = require('should');
mongoose.connect('mongodb://localhost/test');
var CommentSchema = new Schema({
id : ObjectId,
user : String,
@bnoguchi
bnoguchi / GH-377-a.js
Created June 14, 2011 04:49
mongoose GH-377 Example for showing how to update an embedded array member and then re-order the embedded array correctly
var mongoose = require('mongoose')
, Schema = mongoose.Schema ;
mongoose.connect('mongodb://localhost/test');
var EmbeddedDocSchema = new Schema({
date: Date
, name: String
});
@bnoguchi
bnoguchi / GH-386.js
Created June 20, 2011 22:42
Example showing that mongoose GH-386 can't be re-produced
var mongoose = require('mongoose')
, Schema = mongoose.Schema ;
mongoose.connect('mongodb://localhost/test');
var NewsModelSchema = new Schema({
name: String
, title: String
});
@bnoguchi
bnoguchi / mongoose.GH.341.js
Created July 1, 2011 23:52
mongoose GH-341.js - Response to sebm
var mongoose = require('mongoose')
mongoose.connect('mongodb://localhost/sebtest');
var Schema = mongoose.Schema;
var StackItemSchema = new Schema({
blob: Number
});
var StackSchema = new Schema({
@bnoguchi
bnoguchi / connect-zip.GH-2.js
Created July 21, 2011 02:32
Gist for connect-zip Issue GH-2
var assert = require('assert'),
express = require('express'),
gzip = require('connect-gzip');
var app = express.createServer();
app.set('view engine', 'jade');
app.use(gzip.gzip());
app.use(express.bodyParser());
@bnoguchi
bnoguchi / gist:1154982
Created August 18, 2011 19:46
findOrCreateUser
findOrCreateUser: function (sess, accessTok, accessTokExtra, fbUser) {
var promise = this.Promise()
, User = this.User()();
if(sess.auth == null || sess.auth.userId == null) {
User.findOne({'fb.id': fbUser.id}, function (err, foundUser) {
if (foundUser) {
if( foundUser.confirmed ) {
return promise.fulfill(foundUser);
} else {
assignFbDataToUser(foundUser, accessTok, accessTokExtra, fbUser);