Skip to content

Instantly share code, notes, and snippets.

@brainrake
Created June 12, 2015 21:54
Show Gist options
  • Save brainrake/9d3e5271152676bb525f to your computer and use it in GitHub Desktop.
Save brainrake/9d3e5271152676bb525f to your computer and use it in GitHub Desktop.
mg = require 'mongoose'
Global = new mg.Schema
progress: String
RecipeUpload = new mg.Schema
lang: type: String, index: yes
filename: type: String, index: yes
contents: Buffer
sha1: type: String, index: yes
date_uploaded: type: Date, index: -1
date_imported: type: Date, index: -1
import_errors: [String]
Recipe = new mg.Schema
lang: type: String, index: yes
name: type: String
url: type: String, index: yes
author: String
image: String
image_credit: String
source_name: String
#json: Buffer
recipeupload: type: mg.Schema.Types.ObjectId, index:yes
date_imported: Date
ingredients: [String]
ok_groups: [{
group: type: String, index: yes
matched_matchlists: type: [String], index:yes
unmatched_matchlists: type: [String], index:yes
}]
hidden: type: Boolean, default: no
adapt: Boolean, default: no
meal_type: type: String, default: ''
cuisine: type: String, default: ''
Recipe.index {ingredients: 'text'}, {default_language: "none"}
Matchlist = new mg.Schema
lang: type: String, index: yes
group: type: String, index: yes
name: type: String, index: yes
date_filtered: Date
ingredients: [String]
SubstitutionList = new mg.Schema
lang: type: String, index: yes
substitutions: mg.Schema.Types.Mixed
MealTypeList = new mg.Schema
lang: type: String, index: yes
meal_types: [String]
CuisineList = new mg.Schema
lang: type: String, index: yes
cuisines: [String]
connstr = try
require '../connstr'
catch
null
module.exports =
Global: mg.model 'Global', Global
RecipeUpload: mg.model 'RecipeUpload', RecipeUpload
Recipe: mg.model 'Recipe', Recipe
Matchlist: mg.model 'Matchlist', Matchlist
SubstitutionList: mg.model 'SubstitutionList', SubstitutionList
MealTypeList: mg.model 'MealTypeList', MealTypeList
CuisineList: mg.model 'CuisineList', CuisineList
connect_db: (db) -> (n) -> mg.connect (connstr || 'mongodb://localhost/' +
(db || process.env.MONGO_DB || 'foodfilter')), n
disconnect_db: (n) -> mg.disconnect n
drop_db: (n) -> mg.connection.db.dropDatabase n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment