Skip to content

Instantly share code, notes, and snippets.

@devalexandre
Last active October 28, 2015 19:48
Show Gist options
  • Save devalexandre/a9dfc651d5f57c0535fc to your computer and use it in GitHub Desktop.
Save devalexandre/a9dfc651d5f57c0535fc to your computer and use it in GitHub Desktop.
// grab the things we need
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var postSchema = new Schema({
title : {type:String, required:true},
content : {type:String, required:true},
categories:{
name: {type:String, required:true},
}
});
var Post = mongoose.model('Post', postSchema);
// make this available to our users in our Node applications
module.exports = Post;
@Pompeu
Copy link

Pompeu commented Oct 28, 2015

var postSchema = new Schema({
    title  : {type:String, required:true},
    content : {type:String, required:true},
    categories: [
        { name : {type:String, required:true}},
    ]

});

ahh eu sei vai ficar duplicado, no modelo relacional eu faria um join e blz, vale salientar, que mongoDB visa performance de busca, db relacional quer economizar espaço em disco, que não faz muito sentido em um blog por exemplo.

@Pompeu
Copy link

Pompeu commented Oct 28, 2015

var array = ['node','java','angular','node','jenkis'];

var arrayfilter = array.filter(function (item, i, ar) { return ar.indexOf(item) === i;})
["node", "java", "angular", "jenkis"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment