vscode-cosmosdb icon indicating copy to clipboard operation
vscode-cosmosdb copied to clipboard

Cannot create a collection for mongodb for Azure Cosmos DB Emulator

Open ihl396 opened this issue 4 years ago • 20 comments

Does this occur consistently? Yes Repro steps:

  1. Startup Azure Cosmos DB emulator with the /EnableMongoDbEndpoint flag
  2. Connect to mongodb endpoint via vscode extension
  3. Create any database
  4. Add Collection, enter a valid partition key
  5. Error appears: Error: Partition key path /id is invalid for MongoDB API.

Action: cosmosDB.createDocDBCollection Error type: BadRequest Error Message: Partition key path /id is invalid for MongoDB API. ActivityId: 735214de-482e-4aaa-897d-b6cf25aac33f, Microsoft.Azure.Documents.Common/2.11.0

Version: 0.13.0 OS: win32 OS Release: 10.0.18363 Product: Visual Studio Code Product Version: 1.45.1 Language: en

ihl396 avatar Jun 01 '20 06:06 ihl396

Need to look into the emulator scenario. I believe partition keys aren't used for mongo and the action says "DocDB" instead of mongo. It could be an issue where we're confusing database types

ejizba avatar Jun 11 '20 22:06 ejizba

I ran into this one too.

Anyone have thoughts on how to work around it?

houseofyin avatar Sep 18 '20 15:09 houseofyin

Try path "/partition"

TheGeekyM avatar Sep 27 '20 16:09 TheGeekyM

I run into the same issue. Whenever I enable the endpoint alone using the emulator I can't seem to create a container. This issue is caused by the emulator (very irritating).

https://github.com/MicrosoftDocs/azure-docs/issues/67771

hamzahamidi avatar Dec 16 '20 15:12 hamzahamidi

Any updates on this? Cosmos DB emulator is basically unusable for MongoDB as collections cannot be created.

kosjanne avatar Mar 01 '21 19:03 kosjanne

please get this fixed

hoeghen avatar Apr 14 '21 06:04 hoeghen

this issue still persists... has anyone found a workaround?

niklasden avatar Aug 04 '21 12:08 niklasden

Same here, still running into this issue

vs-li avatar Aug 05 '21 22:08 vs-li

We are in September and the issue still persists. Very irritating.

mariomeyrelles avatar Sep 18 '21 21:09 mariomeyrelles

Any updates here? Would really be great if this was fixed!

JameyJohnstonBHP avatar Jan 22 '22 08:01 JameyJohnstonBHP

Same issue here

erik-metz avatar Feb 01 '22 21:02 erik-metz

Same here

IsCaster avatar Apr 05 '22 02:04 IsCaster

This is the critical bug, that doesn't allow to create container and, therefore, work with emulator using mongo endpoint. And more than 1 year and 10 months it is open, unassigned and still in "Backlog Candidates". Small company Microsoft doesn't have enough resources to fix the problem? You might consider making emulator opensource so people will fix it for you

otsomkalov avatar Apr 18 '22 14:04 otsomkalov

Wow. A completely useless emulator for Mongo, although MS markets it as CosmosDB Emulator for Mongo.

tmasselos3 avatar Apr 21 '22 15:04 tmasselos3

Hi everyone,

First off, I'm extremely apologetic for the delay to investigate this issue. There is really no great excuse as why it has been in our backlog for this long when it has been blocking users.

I started investigating this issue, I haven't actually been able to reproduce it.

I am running the current latest version of Azure Cosmos DB Emulator v2.14.6.0 on Windows 11.

Using the cmd terminal with administrator privileges, I started the emulator with the following command: image

Connecting via Attach Emulator... command on the Databases view and selecting Azure Cosmos DB for MongoDB API. It then connects and I am able to create a database, collection, and read/write documents.

image

Need to look into the emulator scenario. I believe partition keys aren't used for mongo and the action says "DocDB" instead of mongo. It could be an issue where we're confusing database types

As mentioned by @ejizba, partition keys aren't used for MongoDB, so it shouldn't be prompting for a partition key when trying to create a collection. I can't really imagine why it would be doing this, but we do cache the attached accounts, so it's possible that some error occurred with serialization or an update broke compatibility.

If you are seeing DocDB or partition keys, could you try detaching and re-connecting to the emulator and see if that resolves anything?

If anybody could provide some more detailed repro steps, including the version of the emulator, how you are initializing the emulator, and a screenshot of your Attached Database Accounts node (similar to what I provided), that would be immensely helpful.

EDIT: Also, I would like to mention that our team only maintains the Azure Databases VS Code extension. We don't actually do any work on the Azure Cosmos DB Emulator-- we are just trying to enable users to connect to it via VS Code. Unfortunately, if the issue is with the emulator itself, there's not much we can do, but I'll keep investigating this to see if there are any workarounds for our users.

nturinski avatar Apr 28 '22 21:04 nturinski

I'm running Ubuntu Desktop 22.04 in Virtual Box (Windows 10 host) and can reproduce this issue. I'm running the emulator with the following docker-compose.yml:

version: "3"
services:
  cosmosdb:
    image: "mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:mongodb"
    ports:
      - "8081:8081"
      - "10251-10254:10251-10254"
    environment:
      - AZURE_COSMOS_EMULATOR_PARTITION_COUNT=10
      - AZURE_COSMOS_EMULATOR_ENABLE_DATA_PERSISTENCE=true
      - AZURE_COSMOS_EMULATOR_ENABLE_MONGODB_ENDPOINT=4.0
    tty: true
    stdin_open: true

I start the container with docker-compose up -d, navigate to https://localhost:8081/_explorer/index.html

I can create a database no problem, but when I try to add a container I get the issue reported in this thread

image

thepaqman avatar Sep 14 '22 17:09 thepaqman

@nturinski the issue is with the built-in explorer UI -- it won't let you create a container without specifying the partition key.

For all others, the workaround is to use another tool like mongo shell...

$ ./mongosh "mongodb://localhost:C2y6yDjf5%2FR%2Bob0N8A7Cgv30VRDJIWEHLM%2B4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw%2FJw%3D%3D@localhost:10255/admin?ssl=true" --tlsAllowInvalidCertificates
Current Mongosh Log ID:	6329518897c01ca257f4e9e7
Connecting to:		mongodb://<credentials>@localhost:10255/admin?ssl=true&directConnection=true&serverSelectionTimeoutMS=2000&tlsAllowInvalidCertificates=true&appName=mongosh+1.5.4
Using MongoDB:		4.0.0
Using Mongosh:		1.5.4

For mongosh info see: https://docs.mongodb.com/mongodb-shell/


To help improve our products, anonymous usage data is collected and sent to MongoDB periodically (https://www.mongodb.com/legal/privacy-policy).
You can opt-out by running the disableTelemetry() command.
globaldb [direct: primary] admin> show dbs
cosmos1  1.00 KiB
globaldb [direct: primary] admin> use cosmos1
switched to db cosmos1
globaldb [direct: primary] cosmos1> db.createCollection('test')
{ ok: 1 }

jasoncwik avatar Sep 20 '22 15:09 jasoncwik

Make sure that the Docker container is also exposing the 10255 port as well, otherwise accessing it through shell/GUI like Studio 3T will not establish a connection for you

kelvien avatar Oct 02 '22 01:10 kelvien

Was everyone with this issue using this portal screen to create the collection?

image

While having the partition key as an input is definitely the issue, our extension doesn't control this page. If you are having issues at that page, you'll have to file an issue with the CosmosDB Emulator team. You can find instructions to do that here.

nturinski avatar Oct 03 '22 17:10 nturinski

Workround for this issue :

1.Start the emulator from command prompt as an administrator with "/EnableMongoDbEndpoint"

  1. Install mongodb compass version 1.28.1 from here https://github.com/mongodb-js/compass/releases/tag/v1.28.1 to connect ,create and manage the database.Use the mongodb connection string from Emulater webpage to connect the database from Mongodb compass.

  2. In the Compass, paste the connectionstring in 'new connection ' view then click the link 'Fill in connection fields indivually'. Go to 'more options ->SSL' then select option 'Unvalidated(insecure)'. Otherwise, connection would fail due to emulator 'self signed' certificate.

  3. Emulater support only wire version 2.0 .So use MongoDB.driver version 2.13.3 from Nuget if .Net

Hope this helps!

tshabeer avatar Nov 13 '22 23:11 tshabeer