嗨,我有這個檔案:
{
"_id" : ObjectId("62792b4a0c9c5a00b6a8e17b"),
"username" : "user_1",
"words" : [
{
"word" : "RATIONAL",
"subwords" : [
"RAT",
"TAN"
]
},
{
"word" : "YOUNGER",
"subwords" : [
"YOU",
"YOUR"
]
}
]
}
我想找到一個具有特定word例如“RATIONAL”并且他的subwords陣列包含一個元素的檔案。
例如,我想檢查是否有一個檔案包含: username:"user_1 in his wordsarray he contains the word:"RATIONAL" and his subwordsarray contains the word"RAT"
類似的東西:
db.users.find({username:"user_1","words":{word:"RATIONAL",subword:"RAT"}}).pretty();
謝謝大家 :)
uj5u.com熱心網友回復:
這應該適合你:
db.users.find({"username": "user_1", "words.word": "RATIONAL", "words.subwords": "RAT"})
您還可以使用 The$elemMatch運算子:
db.users.find({"username": "user_1", "words": { "$elemMatch": { "word": "RATIONAL", "subwords": "RAT" } }})
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/476010.html
