簡體   English   中英

mysql-xdevapi getCollections promise 返回值

[英]mysql-xdevapi getCollections promise return value

我一直在嘗試在我的數據庫模式中 output 數組 collections 。 假設我的 session 工作正常,我會得到一個 Promise{} output,我認為低於這個值是正常的。

        .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
        })

但如果我試圖獲取 promise 中的值

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

它返回給我這些 session 回調函數

 [
  {
    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]
  }
]

這就是 API 的工作方式。 getCollections()方法返回一個Collection實例數組。 每個實例都有特定的方法集。

因此,例如,如果您想獲取集合名稱,您可以執行以下操作:

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

免責聲明:我是 Node.js 的 MySQL X DevAPI 連接器的主要開發人員

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM