0

I've been trying to output the array of collections in my database schema. Assuming my session works, I'd get an Promise{} output below which I think is normal.

        .then(()=>{
            return sess.getSchema('mySchema').getCollection('myCollection')
            .find().fields(['name','age'])
            .execute(row=>{
                console.log(row)
            })
        })
        .then(()=>{
            let r = sess.getSchema('mySchema').getCollections()
            console.log(r)
            return r
        })

but if I tried to get the values in the promise

            let r = sess.getSchema('mySchema').getCollections()
            r.then(v=>{
                console.log(v)
            })

It returns me these session callback functions

 [
  {
    getSession: [Function: getSession],
    add: [Function: add],
    addOrReplaceOne: [Function: addOrReplaceOne],
    count: [Function: count],
    existsInDatabase: [Function: existsInDatabase],
    find: [Function: find],
    getName: [Function: getName],
    getSchema: [Function: getSchema],
    inspect: [Function: inspect],
    modify: [Function: modify],
    remove: [Function: remove],
    removeOne: [Function: removeOne],
    replaceOne: [Function: replaceOne],
    dropIndex: [Function: dropIndex],
    createIndex: [Function: createIndex],
    getOne: [Function: getOne]
  }
]
JEFF
  • 3
  • 3

1 Answers1

0

That's just the way the API works. The getCollections() method returns an array of Collection instances. Each instance has that specific set of methods.

So, for instance, if you want to get the collection names, you can do:

sess.getSchema('mySchema').getCollections()
  .then(collections => {
    console.log(collections.map(c => c.getName()))
  })

Disclaimer: I'm the lead developer of the MySQL X DevAPI Connector for Node.js

ruiquelhas
  • 1,905
  • 1
  • 17
  • 17
  • This should work , Thanks Friend! I did not think of that , I was just using it yesterday. – JEFF May 20 '20 at 08:07
  • @ruiquelhas, I'm new to xdevapi, can you help take a look at https://stackoverflow.com/questions/62853011/mysql-xdevapi-how-to-return-a-successful-status – Jeb50 Jul 12 '20 at 18:37
  • @Jeb50 I've wrote some thoughts there. – ruiquelhas Jul 13 '20 at 09:27