1
votes

I'm trying to retrieve all the documents from a collection stored in azure cosmos db.

However , after the query i get the below error

"MongoError: Command is not supported
    at I:\xxxxx\bot\node_modules\mongodb-core\lib\cursor.js:771:34
    at handleCallback (I:\xxxxx\bot\node_modules\mongodb-core\lib\cursor.js:178:5)
    at setCursorDeadAndNotified (I:\xxx\bot\node_modules\mongodb-core\lib\cursor.js:545:3)
    at nextFunction (I:\xxxxx\bot\node_modules\mongodb-core\lib\cursor.js:770:14)
    at I:\xxxxx\bot\node_modules\mongodb-core\lib\cursor.js:667:7
    at queryCallback (I:\xxxx\bot\node_modules\mongodb-core\lib\cursor.js:263:5)
    at I:\xxxxx\bot\node_modules\mongodb-core\lib\connection\pool.js:541:18
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickDomainCallback (internal/process/next_tick.js:218:9)"

It looks like the cursor is sending this when i'm trying to convert the docs to an array toArray()

heres my function thats trying to retrieve the docs

var getQuestions = function(){
    return new Promise((resolve, reject) => {
        const questionDB = state.db.db('admin')
        const program = questionDB.collection('Version')
        program.find().toArray()
            .then(function(docs){
                console.log('docs : ', docs)
            })
            .catch(function(err){
                console.log('err : ', err)
            })
    })
}

Am i doing something wrong?

1
How are you connecting to cosmos db? where is your connection string?Saleem
You are not doing anything wrong. CosmosDB is not fully compatible with MongoDB, hence the error.kevinadi
Any updates now?Jay Gong

1 Answers

0
votes

I reproduced your issue when I followed the sample code from this doc.

query.js:

var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://***.documents.azure.com:10255/?ssl=true";

MongoClient.connect(url, {user: '***', password: '***'},function(err, db) {
  if (err) throw err;
  var dbo = db.db("db");
  var query = { name: "jay" };
  dbo.collection("coll").find(query).toArray(function(err, result) {
      if (err) throw err;
      console.log(result);
      db.close();
  });
});

error:

enter image description here

Azure Mongo API doesn't support for all of MongoDB features and syntax , please refer to this official doc to check the features and syntax which are supported by Azure Mongo API. toArray method is not found in that list.

Hope it helps you.