Azure-sdk-for-java: Connecting an existing collection to spring data rest using mongodb cosmos API

Created on 23 Mar 2021  路  8Comments  路  Source: Azure/azure-sdk-for-java

Hi,

When i am trying to add a new collection to my database and creating and accessing documents, i am able to do it with the help of this reference - https://docs.microsoft.com/en-us/azure/developer/java/spring-framework/configure-spring-data-mongodb-with-cosmos-db.

When i am trying to access a collection which already exists in my mongo cosmos db, using the same approach, a new collection is getting created, but i am unable to fetch the documents from the existing collection.

Requesting help to point out if i am missing something in this approach.

Thank you

Client azure-spring customer-reported question

All 8 comments

Hi @kushagraThapar , could you help to look into this issue? Thanks~

@yiliuTo - I am not the right owner of the mongo db API for cosmos db. It is still owned and managed by Azure Spring Cloud China team.
Adding @chenrujun to transfer this to the right owners.

Hi @stliu could you please help route this question from @dalavayi?

@chenrujun could u take look of this?

@kushagraThapar thanks for your response, I will work with @chenrujun to investigate this issue.

Hi @dalavayi sorry for the late response. I have run with the document you mentioned but failed to reproduce you problem. Below are my steps:

  1. Follow the doc to establish a project and create a Cosmos db account.
  2. Run the project, and this time it created a collection and inserted two documents.
    image
  3. Then I did some simple modifications as below and ran it again. This time I could see another two documents inserted into the same collection.
    // repository.deleteAll(); // save a couple of customers repository.save(new Customer("Alice1", "Smith1")); repository.save(new Customer("Bob1", "Smith1"));
    image

I uploaded my project of the second running here, could you have a try and see if your issue still exists? Or could you share a sample to help me to reproduce.

@yiliuTo thanks for responding will check the shared link and revert back.

Just a clarification : i was trying to access a collection in the cosmos db which was created by external sources not essentially by mongo sdk, i was facing this error when i try to access that collection. Does this change anything?

Hi @dalavayi , I did another experiments for the case you mentioned. This time I created a collection (called "customer") manually in Azure Portal with one document inserted, and then run the project as I shared. The result is that my manually created collection could be accessed by code and also the existing document was fetched. So if you still encounter this issue, perhaps you could share the way your collection is created.

Was this page helpful?
0 / 5 - 0 ratings