以下答案基于我在 mongo shell 中的测试 -
我刚刚在我的收藏中创建了一个样本。以下是使用“Joe”搜索文档的方法 -
db.sample3.find({"friends":"Joe"})
输出是{ "_id" : ObjectId("5339c9ff0bb9bc1b3a5bf7a4"), "name" : "Nicholas", "friends" : [ "Amy", "Joe", "Amanda" ] }
对于查询db.sample3.find({"friends":"Amy"})
,输出是 -
{ "_id" : ObjectId("5339c9ff0bb9bc1b3a5bf7a4"), "name" : "Nicholas", "friends" : [ "Amy", "Joe", "Amanda" ] }
{ "_id" : ObjectId("5339ca120bb9bc1b3a5bf7a5"), "name" : "John", "friends" : [ "Amy", "Amanda", "Sam", "Steve" ] }
查询 {"friends":"Joe"} 有效。所以,你应该可以在 Mongokit 中使用它。这是我创建的文档 -
db.sample3.find().pretty()
{
"_id" : ObjectId("5339c9ff0bb9bc1b3a5bf7a4"),
"name" : "Nicholas",
"friends" : [
"Amy",
"Joe",
"Amanda"
]
}
{
"_id" : ObjectId("5339ca120bb9bc1b3a5bf7a5"),
"name" : "John",
"friends" : [
"Amy",
"Amanda",
"Sam",
"Steve"
]
}