鍍金池/ 問答/PHP  數(shù)據(jù)庫  HTML/ mongodb的populate嵌套使用問題

mongodb的populate嵌套使用問題

有如下兩個(gè)Model

(1)用戶Model

var usersSchema = new Schema({
    f_id: {
        unique: true,
        type: String
    },
    f_name: String
})

(2)記錄Model

var batchMainSchema = new Schema({
        f_id: {
            unique: true,
            type: String
        },
        f_user_log: [{
            f_option: String,
            f_time: Date,
            f_user_model: { type: Schema.Types.ObjectId, ref: "users" },
        }]
    })

需要在記錄Model中的f_user_log字段中保存用戶操作記錄

請問這種寫法能不能在查詢記錄數(shù)據(jù)時(shí)獲取到f_user_model的值

如下圖中的寫法不能獲取到想要的用戶信息

clipboard.png

請問大伙有沒有相應(yīng)的解決辦法,謝謝?。。?/p>

回答
編輯回答
話寡

populate做不到,用aggregate。

2018年1月7日 16:16