Как вы используете запросы с несколькими схемами в MongooseJS?

У меня есть две схемы: Store и Receipt. Я хочу найти все квитанции, в которых имя магазина равно x. Как бы Вы это сделали?

модели /store.js

var mongoose = require('mongoose'),
    Schema   = mongoose.Schema,
    ObjectId = Schema.ObjectId;

var StoreSchema = new Schema({
    name:       { type: String, require: true },
    address:    { type: ObjectId, ref: 'Address' },
    items:      [ { type: ObjectId, ref: 'Item' } ]
});

mongoose.model( 'Store', StoreSchema );

модели/receipt.js

var mongoose = require('mongoose'),
    Schema   = mongoose.Schema,
    ObjectId = Schema.Types.ObjectId;

var LineItemSchema = new Schema({
    item:   { type: ObjectId, ref: 'item' },
    amount: { type: Number, default: 0 }
});

mongoose.model('LineItem', LineItemSchema);

var ReceiptSchema = new Schema({
    name:       { type: String, default: '' },
    store:      { type: ObjectId, ref: 'Store' },
    items:      [{ type: ObjectId, ref: 'LineItem' }],
    copyNumber: { type: Number, default: 0 } // Number of the receipt of the same store ( Wegmans1, Wegmans2 ...)
});

mongoose.model('Receipt', ReceiptSchema);

person Vongdarakia    schedule 06.07.2014    source источник
comment
JohnnyHK, это не дубликат. Вот в моем вопросе, у меня есть магазины, которые могли бы иметь такое же имя. Например, у меня может быть два Walmart с разными адресами. Пример, на который вы меня сослали, более конкретен.   -  person Vongdarakia    schedule 07.07.2014
comment
Хорошо, в таком случае, вот лучший дубликат: stackoverflow.com/questions/19380738/   -  person JohnnyHK    schedule 07.07.2014
comment
Хорошо, это работает, спасибо!   -  person Vongdarakia    schedule 07.07.2014