Firebase 数据库 snapshot.val() returns 空

Firebase DB snapshot.val() returns null

我正在使用 firebase-admin (5.13.1) NodeJS 库,但无法让 .val() 处理 .on('value') 函数。

  var key = "someFirebaseKey";
  db.ref().child('search/response').child(key).on('value', function(snapshot) {
    console.log(snapshot.val());
  })

这个returnsnull.

但是,snapshot 具有以下值:

DataSnapshot {
  node_: 
   ChildrenNode {
     children_: 
      SortedMap {
        comparator_: [Function: NAME_COMPARATOR],
        root_: LLRBEmptyNode {} },
     priorityNode_: null,
     indexMap_: IndexMap { indexes_: [Object], indexSet_: [Object] },
     lazyHash_: '' },
  ref_: 
   Reference {
     repo: 
      Repo {
        repoInfo_: [RepoInfo],
        app: [FirebaseApp],
        dataUpdateCount: 2,
        statsListener_: null,
        eventQueue_: [EventQueue],
        nextWriteId_: 3,
        interceptServerDataCallback_: null,
        onDisconnect_: [SparseSnapshotTree],
        persistentConnection_: [PersistentConnection],
        stats_: [StatsCollection],
        server_: [PersistentConnection],
        statsReporter_: [StatsReporter],
        transactionQueueTree_: [Tree],
        infoData_: [SnapshotHolder],
        infoSyncTree_: [SyncTree],
        serverSyncTree_: [SyncTree],
        __database: [Database] },
     path: Path { pieces_: [Array], pieceNum_: 0 },
     queryParams_: 
      QueryParams {
        limitSet_: false,
        startSet_: false,
        startNameSet_: false,
        endSet_: false,
        endNameSet_: false,
        limit_: 0,
        viewFrom_: '',
        indexStartValue_: null,
        indexStartName_: '',
        indexEndValue_: null,
        indexEndName_: '',
        index_: PriorityIndex {} },
     orderByCalled_: false },
  index_: PriorityIndex {} }

关于方向或如何调试 Firebase 对象的任何想法?

我花了最后一天半的时间试图解决这个问题,尝试了几种不同的调试尝试,阅读了大部分 Whosebug 线程,但无济于事。

如有任何帮助,我们将不胜感激!

根据文档,当查询位置没有数据时,val() returns null:

Depending on the data in a DataSnapshot, the val() method may return a scalar type (string, number, or boolean), an array, or an object. It may also return null, indicating that the DataSnapshot is empty (contains no data).

不能直接使用DataSnapshot 对象的内部内容。请改用 public API。