簡體   English   中英

Mongoose 查詢嵌套模式

[英]Mongoose query for nested schema

我有以下架構:

const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const ProjectSchema = require('./project.js')

const ClientManagerSchema = new Schema({
    name : { type : String,  required : true},
    project : [ProjectSchema]
});

const  ClientManager = mongoose.model('clientManager' , ClientManagerSchema);

module.exports = ClientManager; 

在 clientmanager 模式中,還有另一個如您所見。 我想根據 ProjectSchema 中的值查詢數據庫。

我不確定該怎么做,但我嘗試過類似的方法:

const find = () => {
   ClientManagers.find({ProjectSchema}).then(e => {
       console.log(e);
   });
}

但是,這給了我一個空數組。

簡單易行,你可以用點符號來引用:

const result = await ClientManager.find({ 'project.projectName': 'Foo' })

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM