const Schema = new Schema({
queueId: {
type: String,
required: true,
index: {
unique: true
}
},
players: {
type: [
{
ID: {
type: String,
required: true,
index: {
unique: true
},
default: 'null'
},
name: {
type: String,
required: true,
default: 'null',
},
queueId: {
type: String,
required: true,
default: 'null'
}
}
],
required: true,
default: []
},
isAvailable: {
type: Boolean,
required: true,
default: true
},
isFull: {
type: Boolean,
required: true,
default: false
}
});
如何使用findOne()從中獲取players陣列的物件
我目前正在嘗試此代碼,但它回傳null
const doc = await List.findOne({ players: { ID: 'id' } });
基本上players是一個陣列,我想從玩家物件陣列中找到 ID 并獲取檔案。
uj5u.com熱心網友回復:
db.collection.find({
"players.ID": "1"
},
{
"players.$": 1
})
mongoplayground
db.collection.find({
"players.ID": "1"
})
mongoplayground
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/437003.html
標籤:javascript mongodb 猫鼬
上一篇:Kubernetesnginx部署ERR_CONNECTION_REFUSED
下一篇:如何在mongo中按_id分組
