Brian Waugh
Brian Waugh

Reputation: 53

Cannot .find() on CosmosDB via MongoAPI nor through Azure Portal "Data Explorer", Only via documentDB API does it work

I get a 500 internal server error from MongoAPI through Robo3t and Azure Portal.

I have dropped my database and collection several times, inserted some sample records and tried viewing in the Azure Portal's "Data Explorer" or Robo3t via MongoDB API and am completely unable to view all records. The only way i'm able to view records is from a straight documentDB .query() 'Select *'.

Via Robo3t strangely i'm able to connect perfectly, view stats, insert records and view the specific records I inserted (from Robo3t) but completely unable to view all records or use a .find({}). All of this was working just fine a few days ago. I've tried this from multiple devices on multiple networks.

Document DB host is connected via 443 port while Robo3t is via 10255 port. I cannot connect differently to either APIs I noticed.

I'm typically inserting via documentDB api.

Here are some screenshots:

db.getCollection('test').stats()

Inserting 2 of the same record

finding those 2 records

db.getCollection('test').find({})

Getting documents via documentDB query via node.js successfully pulling all records

Trying to find one of those documentDB query objects in Robot3t

Again

Unable to get anything via Data Explorer

Upvotes: 2

Views: 548

Answers (1)

Matias Quaranta
Matias Quaranta

Reputation: 15583

The issue is the one you mentioned, you are inserting documents using the DocumentDB API into a Mongo API account. Mongo API accounts are meant to be used only with Mongo-enabled clients/SDKs.

Portal and third party applications fail because they are using MongoDB protocol to read the documents, these documents you stored via the DocumentDB API don't have the required MongoDB attributes (for example, "_id"). When you insert documents using a Mongo client, the client will make sure none of the required MongoDB attributes are missing (and in the case of the "_id" identifier, autogenerate it).

When you run the find() command, the driver is encountering documents that fail to comply with the required MongoDB attributes (those that were inserted with DocumentDB API) and abort.

If you want to interact using the DocumentDB API, use a SQL Account. If your applications use the MongoDB protocol and you need to use a Mongo Account, store the documents using a Mongo-enabled client.

Similar case on another SO question.

To solve your issue, re-create the collection and only store documents using Mongo API clients/applications using Mongo SDK.

Upvotes: 1

Related Questions