我已经使用yeoman生成器安装了MEAN堆栈,我想实现一个查询,如果存在具有特定属性的给定值的文档,则返回true。
这是模特:
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
var FirstSchema = new Schema({
field1: {
type: Number,
trim: true,
default: ''
},
user: {
type: Schema.ObjectId,
ref: 'User'
},
});
var SecondSchema = new Schema({
field1: {
type: Number,
trim: true,
default: ''
},
field2: {
type: String,
},
user: {
type: Schema.ObjectId,
ref: 'User'
},
});
mongoose.model('First', FirstSchema);
mongoose.model('Second', SecondSchema);
在创建Second对象期间,我分配了$ scope.field2 = $ stateParams.firstId;
yeoman在客户端生成的给定查询是:
$scope.find = function() {
$scope.firsts = Firsts.query();
};
如何查询First._id == Second.field2?