gpt4 book ai didi

json - 来自 Powershell 的 Mongodb Find() 查询

转载 作者:可可西里 更新时间:2023-11-01 10:29:55 26 4
gpt4 key购买 nike

对于下面的 Json 文件,我有一个 mongodb 查询只选择文档的 "Car" 部分:

db.collection.find({_item:"Home"}, {"Car":1, "_id":0})

如何在 Powershell 中编写此查询?

{
"_id" : 1,
"_item": "Home",
"Car": [
{"name": "BMW", "model": "series 3"},
{"name": "Audi", "model": "A4"}
],
"Fruit": [
{"name": "Banana", "color": "Yellow"},
{"name": "Apple", "color": "Red"}
]
}

最佳答案

$databaseName = "database"
$collectionName = "collection"
$client = New-Object -TypeName MongoDB.Driver.MongoClient -ArgumentList "mongodb://localhost:27017"
$server = $client.GetServer()
$database = $server.GetDatabase($databaseName)
$collection = $database.GetCollection($collectionName)

$query = MongoDB.Driver.Builders.Query.EQ("_item","HOME")
$results = $collection.Find($query).SetFields(Fields.Exclude("_id").Include("Car"))

关于json - 来自 Powershell 的 Mongodb Find() 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27752692/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com