These are chat archives for Automattic/mongoose

22nd
Jul 2018
belubit
@belubit
Jul 22 2018 00:00
I would like to get all groups, and in each group I would like to populate it's item field with all the items which were created after the group was created.
as the items are shared between many users, so found it most efficient to only store an item once
so a user creates a group, populates it with items, but some of those items were created before the group was created, so I don't want those to show up
hopefully that makes more sense, although I think I am starting to confuse myself now
No, wait, I missed a step
the items contain an array, which is updated daily, so it's the array in the item whose date needs to be greater than the group date
belubit
@belubit
Jul 22 2018 00:04
I think that looks promising yes!
belubit
@belubit
Jul 22 2018 00:21
I think I am going to have to rethink my models
Ben Chiciudean
@benydc
Jul 22 2018 13:34
I’m trying to nest shema with subDocument but it comes up with error saying:
Did you try nesting Schemas? You can only nest using refs or arrays.
Berian
@chaiwa-berian
Jul 22 2018 13:36
@benydc Kindly share code snippet!
Ben Chiciudean
@benydc
Jul 22 2018 13:37
import { SeatingMap } from "./seating-map.schema";

var eventSchema: mongoose.Schema = new mongoose.Schema({
    name: String,
    topicName: String,
    location: { latitude: Number, longitude: Number },
    locationName: String,
    ticketValues: [{ type: mongoose.Schema.Types.ObjectId, ref: 'TicketValue' }],
    products: [{ type: mongoose.Schema.Types.ObjectId, ref: 'EventProduct' }],
    purchases: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Purchase' }],
    createdAt: { type: Date, default: Date.now },
    eventDate: [{ start: Date, end: Date }],
    aboutDescription: String,
    images: { logo: String, header: String, background: String },
    contact: { email: String, phone: Number, website: String },
    social: { facebook: String, twitter: String, instagram: String },
    seatingMap: SeatingMap
});
var seatingMapSchema: mongoose.Schema = new mongoose.Schema({
    svg: String,
    location: { latitude: Number, longitude: Number },
    seatMap: [{ sector: String, seats: [String] }]
});

export let SeatingMap = mongoose.model<ISeatingMap>('SeatingMap', seatingMapSchema, 'seating_maps', true);
TypeError: Undefined type `Model` at `seatingMap`
Berian
@chaiwa-berian
Jul 22 2018 13:47
Where is ISeatingMap declared? Is is an interface?
Kev
@lineus
Jul 22 2018 13:49
@benydc SeatingMap is being exported as a Model. If you want to use the schema as an embedded doc you'll need to export the schema instead.
Ben Chiciudean
@benydc
Jul 22 2018 13:49
ahhh
yes, you are right!