When the applet cloud database query function result has been null

When querying the database, use the function to the cloud

// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()

const db = cloud.database()  ///////////////////////////////
exports.main = async (event, context) => {

  var nickname = event.nickname
  try {
    return await db.collection('user_info').where({
      nickName: nickname
    }).get()
  } catch (e) {
    console.error(e)
  }
}

 

Call follows

wx.cloud.callFunction ({ 
          // function name cloud 
          name: 'searchByNickname', 
          Data: { 
            Nickname: pageData.data.nickname 
          } 
        }). the then (RES => { 
          the console.log ( "through nickName as:", pageData .data.nickname, "Finding user information:", RES) 
        })

  

 

But a start has been the result null, later found not written in the cloud function const db = cloud.database (), moreover, do not see an error message related to cloud looks like a function, or if there is no definition of db calls should have prompt.

 

When developing the best cloud cloud database query function, there will be unexpected bug if you do not use cloud functions of words! ! !

Guess you like

Origin www.cnblogs.com/Guhongying/p/10990196.html