jeroen / mongolite

Fast and Simple MongoDB Client for R
https://jeroen.github.io/mongolite/
284 stars 64 forks source link

Cannot connect with Azure CosmosDB - Server reports wire version 2, but this version of libmongoc requires at least 3 #167

Closed ibombonato closed 5 years ago

ibombonato commented 5 years ago

I am trying to connect to Azure CosmosDB (Mongo API) and when trying to connect, it gives a message telling that libmongc requires version 3.

How to reproduce it using Azure Cosmos Emulator

After install the CosmosDB Local Emulator, juts start it and go to R.

library(mongolite)
con <- mongo(url = "mongodb://localhost:C2y6yDjf5%2FR%2Bob0N8A7Cgv30VRDJIWEHLM%2B4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw%2FJw%3D%3D@localhost:10255/admin?ssl=true")
# Error: Server at localhost:10250 reports wire version 2, but this version of libmongoc requires at least 3 (MongoDB 3.0)

I connect to the emulator using Robomongo, (https://dotnetthoughts.net/connecting-to-azure-cosmos-db-emulator-from-robomongo/) and it says the version is 3.2.0:

db.version()
3.2.0
db.runCommand( { buildInfo: 1 } )
{
    "_t" : "BuildInfoResponse",
    "ok" : 1,
    "version" : "3.2.0",
    "gitVersion" : "45d947729a0315accb6d4f15a6b06be6d9c19fe7",
    "targetMinOS" : "Windows 7/Windows Server 2008 R2",
    "modules" : [],
    "allocator" : "tcmalloc",
    "javascriptEngine" : "Chakra",
    "sysInfo" : "deprecated",
    "versionArray" : [ 
        3, 
        2, 
        0, 
        0
    ],
    "bits" : 64,
    "debug" : false,
    "maxBsonObjectSize" : 524288,
    "openssl" : {
        "running" : "OpenSSL 1.0.1p-fips 9 Jul 2015",
        "compiled" : "OpenSSL 1.0.1p-fips 9 Jul 2015"
    }
}
jeroen commented 5 years ago

@ajdavis what does this error mean? I'm guessing the server version of openssl is too old?

ajdavis commented 5 years ago

No, it's a CosmosDB issue. It reports maxWireVersion 2, but the C Driver requires a server that supports wire protocol version 3 or later. I'd report it to Microsoft.

jeroen commented 5 years ago

@ibombonato not much I can do here then. You can try installing an old version such as mongolite 1.6, which was the last version to support wire version 2:

install.packages('mongolite', repos = 'https://cran.microsoft.com/snapshot/2018-08-01')
ibombonato commented 5 years ago

@ajdavis I don't know if this changes anything, but I run a command here to see the wire version and it reports 2 when using emulator, but 5 at production environment. So in theory, I guess I should be able to connect to the production environment, but I cant anyway.

Production Environment:

db.runCommand( { isMaster: 1 } )
{
    "_t" : "IsMasterResponse",
    "ok" : 1,
    "ismaster" : true,
    "maxBsonObjectSize" : 16777216,
    "maxMessageSizeBytes" : 4194304,
    "maxWriteBatchSize" : 1000,
    "minWireVersion" : 0,
    "maxWireVersion" : 5,
    "localTime" : ISODate("2018-12-12T18:59:23.171Z"),
    "setVersion" : 1,
}

Emulator:

{
    "_t" : "IsMasterResponse",
    "ok" : 1,
    "ismaster" : true,
    "maxBsonObjectSize" : 16777216,
    "maxMessageSizeBytes" : 4194304,
    "maxWriteBatchSize" : 1000,
    "minWireVersion" : 0,
    "maxWireVersion" : 2,
    "localTime" : ISODate("2018-12-12T18:58:10.408Z")
}
ajdavis commented 5 years ago

Hi, I don't have any experience with Azure or CosmosDB. What emulator are you referring to please?

ibombonato commented 5 years ago

There is a software to emulate Azure Cosmos DB at your on machine, that way you can develop/test things out without the need to pay for it on Azure itself.

CosmosDB Local Emulator - (https://docs.microsoft.com/en-us/azure/cosmos-db/local-emulator)

So, according to my previous post, at the emulator, maxWireVersion is 2, so it is a Microsoft problem for sure... But when I run at CosmosDB on Azure, not the emulator, maxWireVersion is 5, so the problem should not happen, but it is happen anyway.

What command do you use to get the wire version? Is it db.runCommand( { isMaster: 1 } ) ? Or is something else? That way I can test it here.

I can create/provide access to a sample database in CosmosDB at Azure itself if you need to test something out.

ibombonato commented 5 years ago

@ibombonato not much I can do here then. You can try installing an old version such as mongolite 1.6, which was the last version to support wire version 2:

install.packages('mongolite', repos = 'https://cran.microsoft.com/snapshot/2018-08-01')

fwiw, It is working with this version.

Thank you!

ajdavis commented 5 years ago

Right, run db.runCommand({isMaster: 1}). The logic MongoDB drivers use to check compatibility is specified here:

https://github.com/mongodb/specifications/blob/master/source/server-discovery-and-monitoring/server-discovery-and-monitoring.rst#checking-wire-protocol-compatibility

MongoDB drivers currently define clientMinWireVersion as 3, and clientMaxWireVersion as 6.

rtreacy commented 5 years ago

I reported this to Microsoft in August (Support Request Number - 118082418860894). After some back and forth they acknowledged that it was their issue and it was supposed to be fixed in September. I haven't been following it since then, as I was unable to continue use of mongolite because I need GridFS support

ajdavis commented 5 years ago

mongolite does have GridFS support now, right?

jeroen commented 5 years ago

Yes it does, but he isn't able to use the latest version of the C driver because his CosmosDB server only supports wire version 2. This is a bug in CosmosDB, we can't fix this in the client.

rtreacy commented 4 years ago

This is now fixed in Cosmos - but you have to specify to use Server Version 3.6 when you set up your Cosmos DB account

pedrodpduarte commented 4 years ago

@rtreacy I have specified Server Version 3.6 and still don't work in mongolite last version. Only with https://cran.microsoft.com/snapshot/2018-08-01.

"Server at cdb-ms-prod-eastus1-fd25.documents.azure.com:10255 reports wire version 2, but this version of libmongoc requires at least 3 (MongoDB 3.0)"

Any advice?

rtreacy commented 4 years ago

@pedrodpduarte The connection string has a slightly different format. Are you using the new connection string generated when you set up the new 3.6 Cosmos DB account, from the portal under Settings -> Connection String?