Skip to content

Instantly share code, notes, and snippets.

@laerciobernardo
Created April 27, 2018 21:18
Show Gist options
  • Save laerciobernardo/42bca9dca362dd64d55558aa8fb4fc95 to your computer and use it in GitHub Desktop.
Save laerciobernardo/42bca9dca362dd64d55558aa8fb4fc95 to your computer and use it in GitHub Desktop.
'use strict'
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
let avaliationItemSchema = new Schema({
description: String,
_type: {type: Schema.Types.ObjectId, ref: 'avaliationType'},
active: Boolean,
});
//SubDocuments referred qrcode will be genereted
let tagSchema = new Schema({
name: String,
description: String,
active: Boolean,
main: Boolean, //Describe what tag will be show when other methods company identification like (GPS)
avaliationItems:[avaliationItemSchema]
});
let companySchema = new Schema({
active: Boolean,
deleted: Boolean,
cnpj: String,
ie: String,
companyName: String,
tradingName: String,
urlLogo: String,
address: {
streetType: String,
street: String,
number: Number,
complement: String,
district: String,
zipCode: Number,
city: String,
state: String,
country: String
},
phone: String,
emails: [String],
tags: [tagSchema]
});
module.exports = mongoose.model('company', companySchema);
@laerciobernardo
Copy link
Author

tenho uma função no meu controller para buscar uma company, e queria fazer um populate do atributo _type do Schema avaliationSchema, tentei assim mas não funcionou
const get = (uid) => { let query = {"_id": uid.toObjectId()}; return Model.findOne(query).populate('tags.avaliationItems._tagType'); };

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