0
Mongo令我瘋狂。我有這些模式:無法通過Mongo中的點符號搜索子文檔(mongoose)
var userSchema = new Schema({
username: {
type: String,
require: true,
unique: true
},
password: {
type: String,
require: true,
}
});
var User = mongoose.model('user', userSchema);
var deviceSchema = new Schema({
name: {
type: String,
require: true,
unique: true
},
type: String,
lastvalue: {
type: Schema.ObjectId,
ref: 'event'
},
owner: {
type: Schema.ObjectId,
ref: 'user',
require: true
},
apiKey: {
type: String,
unique: true,
default: function() {
return crypto.randomBytes(64).toString('hex');
}
}
});
var Device = mongoose.model('device', deviceSchema);
我想檢索用戶的所有設備。所以: Device.find({'owner.username': req.params.username})
但它返回一個空數組! 我也試過: Device.find({'owner.username': req.params.username}, {'owner':1})
Device.find({'owner.username': req.params.username}, {'owner.$':1)
沒有任何的運氣...... 我已經搜查了整個互聯網,但我無法找到任何有用的!
我可以在單個查詢中執行嗎? – dzervas