简体   繁体   中英

How do I install MongoDB driver for PowerShell using Install-Package?

I am trying to interact with MongoDB from powershell and need to install the driver package. Per instructions from https://www.nuget.org/packages/mongodb.driver I issue the command:

Install-Package MongoDB.Driver -Version 2.8.0

But I get an error:

Install-Package : A parameter cannot be found that matches parameter name 'Version'.
At line:1 char:32
+ Install-Package MongoDB.Driver -Version 2.8.0
+                                ~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Install-Package], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage

Not sure how to proceed.

> Get-PackageSource

Name                             ProviderName     IsTrusted  Location                                                                              
----                             ------------     ---------  --------                                                                              
PSGallery                        PowerShellGet    False      https://www.powershellgallery.com/api/v2                                              
nuget.org                        NuGet            False      https://api.nuget.org/v3/index.json                                                   
My Downloads                     NuGet            False      C:\Users\Richard\Downloads                                                            

I tried downloading and installing from there, but still get an error:

> Install-Package -scope currentuser mongodb.driver

The package(s) come(s) from a package source that is not marked as trusted.
Are you sure you want to install software from 'My Downloads'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): y
Install-Package : One or more errors occurred.
At line:1 char:1
+ Install-Package -scope currentuser mongodb.driver
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: ($TXkgRG93bmxvYW...2ZXI=\Mi44LjA=\:String) [Install-Package], Exception
    + FullyQualifiedErrorId : One or more errors occurred.,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage

you can use .NET CLI and use this command

dotnet add package MongoDB.Driver --version 2.8.0

or

dotnet add package MongoDB.Driver --version 2.9.0-beta1

or remove version to install last stable version automaticly like:

Install-Package MongoDB.Driver

also see this articel :

https://docs.microsoft.com/en-us/nuget/consume-packages/package-restore-troubleshooting

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM