0

I'm using Firebase Realtime DB. I am trying to query posts by a specific value (ups). Each post has a random identifier as well as a number of attributes.

To query the database, I ran the following code in my index.js document:

  var firebase = require("firebase");
    firebase.initializeApp({
      databaseURL: "<URL>"
    });
    var dbRef = firebase.database().ref('posts/rice/content');
    var bestPosts = dbRef.orderByChild('ups');
    console.log(bestPosts)

But instead of printing out data, it printed out a bunch of info about my query itself.

Query {   repo: <ref *1> Repo {
    repoInfo_: RepoInfo {
      secure: true,
      namespace: 'librexreacttester',
      webSocketOnly: false,
      persistenceKey: '',
      includeNamespaceInQueryParams: false,
      host: 'librexreacttester.firebaseio.com',
      domain: 'firebaseio.com',
      internalHost: 'librexreacttester.firebaseio.com'
    },
    app: FirebaseAppImpl {
      firebase_: [Object],
      isDeleted_: false,
      name_: '[DEFAULT]',
      automaticDataCollectionEnabled_: false,
      options_: [Object],
      container: [ComponentContainer]
    },
    dataUpdateCount: 0,
    statsListener_: null,
    eventQueue_: EventQueue { eventLists_: [], recursionDepth_: 0 },
    nextWriteId_: 1,
    interceptServerDataCallback_: null,
    onDisconnect_: SparseSnapshotTree { value: null, children: Map(0) {} },
    persistentConnection_: PersistentConnection {
      repoInfo_: [RepoInfo],
      applicationId_: undefined,
      onDataUpdate_: [Function: bound ],
      onConnectStatus_: [Function: bound ],
      onServerInfoUpdate_: [Function: bound ],
      authTokenProvider_: [FirebaseAuthTokenProvider],
      authOverride_: undefined,
      id: 0,
      log_: [Function (anonymous)],
      interruptReasons_: {},
      listens: Map(0) {},
      outstandingPuts_: [],
      outstandingPutCount_: 0,
      onDisconnectRequestQueue_: [],
      connected_: false,
      reconnectDelay_: 1000,
      maxReconnectDelay_: 300000,
      securityDebugCallback_: null,
      lastSessionId: null,
      establishConnectionTimer_: Timeout {
        _idleTimeout: 1,
        _idlePrev: [Timeout],
        _idleNext: [TimersList],
        _idleStart: 259,
        _onTimeout: [Function (anonymous)],
        _timerArgs: undefined,
        _repeat: null,
        _destroyed: false,
        [Symbol(refed)]: true,
        [Symbol(asyncId)]: 4,
        [Symbol(triggerId)]: 1
      },
      visible_: true,
      requestCBHash_: {},
      requestNumber_: 0,
      realtime_: null,
      authToken_: null,
      forceTokenRefresh_: false,
      invalidAuthTokenCount_: 0,
      firstConnection_: true,
      lastConnectionAttemptTime_: null,
      lastConnectionEstablishedTime_: null
    },
    stats_: StatsCollection { counters_: {} },
    server_: PersistentConnection {
      repoInfo_: [RepoInfo],
      applicationId_: undefined,
      onDataUpdate_: [Function: bound ],
      onConnectStatus_: [Function: bound ],
      onServerInfoUpdate_: [Function: bound ],
      authTokenProvider_: [FirebaseAuthTokenProvider],
      authOverride_: undefined,
      id: 0,
      log_: [Function (anonymous)],
      interruptReasons_: {},
      listens: Map(0) {},
      outstandingPuts_: [],
      outstandingPutCount_: 0,
      onDisconnectRequestQueue_: [],
      connected_: false,
      reconnectDelay_: 1000,
      maxReconnectDelay_: 300000,
      securityDebugCallback_: null,
      lastSessionId: null,
      establishConnectionTimer_: Timeout {
        _idleTimeout: 1,
        _idlePrev: [Timeout],
        _idleNext: [TimersList],
        _idleStart: 259,
        _onTimeout: [Function (anonymous)],
        _timerArgs: undefined,
        _repeat: null,
        _destroyed: false,
        [Symbol(refed)]: true,
        [Symbol(asyncId)]: 4,
        [Symbol(triggerId)]: 1
      },
      visible_: true,
      requestCBHash_: {},
      requestNumber_: 0,
      realtime_: null,
      authToken_: null,
      forceTokenRefresh_: false,
      invalidAuthTokenCount_: 0,
      firstConnection_: true,
      lastConnectionAttemptTime_: null,
      lastConnectionEstablishedTime_: null
    },
    statsReporter_: StatsReporter {
      server_: [PersistentConnection],
      statsToReport_: {},
      statsListener_: [StatsListener]
    },
    transactionQueueTree_: Tree { name_: '', parent_: null, node_: [TreeNode] },
    infoData_: SnapshotHolder { rootNode_: [ChildrenNode] },
    infoSyncTree_: SyncTree {
      listenProvider_: [Object],
      syncPointTree_: [ImmutableTree],
      pendingWriteTree_: [WriteTree],
      tagToQueryMap: Map(0) {},
      queryToTagMap: Map(0) {}
    },
    serverSyncTree_: SyncTree {
      listenProvider_: [Object],
      syncPointTree_: [ImmutableTree],
      pendingWriteTree_: [WriteTree],
      tagToQueryMap: Map(0) {},
      queryToTagMap: Map(0) {}
    },
    __database: Database {
      repo_: [Circular *1],
      root_: [Reference],
      INTERNAL: [DatabaseInternals]
    }   },   path: Path { pieces_: [ 'posts', 'rice', 'content' ], pieceNum_: 0 },   queryParams_: QueryParams {
    limitSet_: false,
    startSet_: false,
    startNameSet_: false,
    endSet_: false,
    endNameSet_: false,
    limit_: 0,
    viewFrom_: '',
    indexStartValue_: null,
    indexStartName_: '',
    indexEndValue_: null,
    indexEndName_: '',
    index_: PathIndex { indexPath_: [Path] }   },   orderByCalled_: true }

What's going on with this output, and why am I not getting my data?

1 Answer 1

1

You code doesn't read the data yet. Instead the bestPosts = dbRef.orderByChild('ups') merely creates a query, that you can then execute by attaching a listener to it.

bestPosts.once("value").then(function(snapshot) {
  console.log(snapshot.val());
})

I highly recommend reading the Firebase documentation on reading data from the database, as a few hours there will save you a lot of time down the line.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.