对于以下 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/