Firebase数据库查询打印数据库信息,而不是数据



我使用的是Firebase实时数据库。我正试图通过一个特定的值(ups(来查询帖子。每个帖子都有一个随机标识符以及一些属性。

为了查询数据库,我在index.js文档中运行了以下代码:

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

但它没有打印出数据,而是打印出了一堆关于我的查询本身的信息。

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 }

这个输出是怎么回事,为什么我没有得到我的数据?

您的代码还没有读取数据。相反,bestPosts = dbRef.orderByChild('ups')只是创建一个查询,然后您可以通过将侦听器附加到它来执行该查询

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

我强烈建议阅读有关从数据库中读取数据的Firebase文档,因为几个小时后会为您节省大量时间。

最新更新