Skip to content

Instantly share code, notes, and snippets.

View bnoguchi's full-sized avatar

Brian Noguchi bnoguchi

View GitHub Profile
@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-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-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-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-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-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-248.js
Created June 8, 2011 23:36
GH-248 Working Example
// This shows that GH-248 is no longer relevant
var mongoose = require('mongoose')
, Schema = mongoose.Schema ;
mongoose.connect('mongodb://localhost/test');
var EmbeddedDocSchema = new Schema({
inner_label: String
});
@bnoguchi
bnoguchi / GH-247.js
Created June 8, 2011 23:28
Correct example for GH-247
// Example works also works if you swap the commented lines into the code, and comment
// the corresponding uncommented lines.
var mongoose = require('mongoose')
, Schema = mongoose.Schema ;
mongoose.connect('mongodb://localhost/test');
var Item = new Schema({
cat_id: Number
@bnoguchi
bnoguchi / enum-access.js
Created May 3, 2011 09:19
How to access enumValues in mongoose from a Model or Document
var mongoose = require('./index')
, TempSchema = new mongoose.Schema({
salutation: {type: String, enum: ['Mr.', 'Mrs.', 'Ms.']}
});
var Temp = mongoose.model('Temp', TempSchema);
console.log(Temp.schema.path('salutation').enumValues);
var temp = new Temp();
console.log(temp.schema.path('salutation').enumValues);
@bnoguchi
bnoguchi / bug-334.js
Created April 26, 2011 21:24
Reply to mongoose GH-334
var mongoose = require('mongoose')
, Schema = mongoose.Schema
, assert = require('assert');
var subSchema = new Schema({
name : String ,
subObj : { subName : String }
});
var schema = new Schema ({ name : String , arrData : [ subSchema] });