1

I recently created an cosmosdb account which uses Mongo API. when I create new collections the only database it uses is "admin".

I tried attaching the db name like testdb to the url but that didn't work. I tried mongo shell to create a db but it didn't work either.

1 Answer 1

1

Either create your database ahead of time (using either the portal or the Azure SDK), or create via MongoDB.

Not sure how you tried attaching to testdb but from the shell, you should be able to execute:

use testdb

Once you do this, you can execute something like

db.newcollection.save({foo:"bar"})

This will result in a new collection created, within testdb. You can see this via show dbs:

globaldb:PRIMARY> show dbs
admin          0.000GB
testdb         0.000GB

Note: When you create a collection implicitly this way (vs creating explicitly via either the portal or the Cosmos DB SDK), you will get a default RU setting for the collection (1000 RU currently), and would need to adjust accordingly via the portal afterward to suit your needs.

Sign up to request clarification or add additional context in comments.

3 Comments

How can I access this using the url should I just use the /{database} like in any mongodb instance.
That's correct. Just specify whatever database you want, on the commandline, with /<dbname>. Then, when you create your new collection, it will be created in that database (and if the database doesn't exist yet, it will be created when you go to save a doc in your new collection).
the problem was that database doesn't show up when using the show dbs; command if u don't create a collection. got it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.