Firebase数据库查询错误:子级不是函数

时间:2018-11-29 16:34:39

标签: node.js firebase firebase-realtime-database

我在Firebase中有一个表let string = "dots.and-hyphens" let array = string.components(separatedBy: CharacterSet(charactersIn: ".-")) ,其中包含这些数据

users

导入后我得到了

enter image description here

我尝试使用NodeJS进行查询

{
  "users" :
  [
   {"id": 1,
     "fcmToken" : "APA91bHJAzXe384OEYvfk4bKsyS1NQvteph7DwG7JRIMm_HuXg8EeNllVrsSi0v9W_Gh95ezbOStp3ZWuWl0AzFKxMaCOjN81yiz7A5qhkONrd7lP2CTkUbFErw28r3ONTLvo8c8sO7hdiWY78iar8s:APA91bHJAzXe384OEYvfk4bKsyS1NQvteph7DwG7JRIMm_HuXg8EeNllVrsSi0v9W_Gh95ezbOStp3ZWuWl0AzFKxMaCOjN81yiz7A5qhkONrd7lP2CTkUbFErw28r3ONTLvo8c8sO7h",
     "fName" : "John",
     "lName" : "Doe",
     "phone" : "9786770861"
   },
   {"id": 2,
     "fcmToken" : "APA91bHJAzXe384OEYvfk4bKsyS1NQvteph7DwG7JRIMm_HuXg8EeNllVrsSi0v9W_Gh95ezbOStp3ZWuWl0AzFKxMaCOjN81yiz7A5qhkONrd7lP2CTkUbFErw28r3ONTLvo8c8sO7hdiWY78iar8s:APA91bHJAzXe384OEYvfk4bKsyS1NQvteph7DwG7JRIMm_HuXg8EeNllVrsSi0v9W_Gh95ezbOStp3ZWuWl0AzFKxMaCOjN81yiz7A5qhkONrd7lP2CTkUbFErw28r3ONTLvo8c8sO7h",
     "fName" : "Jane",
     "lName" : "Doe",
     "phone" : "6178779690"
   }

 ]
}

我一直收到此错误:

/*================================
=            Database            =
================================*/

var admin = require("firebase-admin");

var serviceAccount = require('/Users/john/Desktop/Apps/APNS/node/mhn-app-firebase-adminsdk-bs45c-5ac3770488.json');

var firebase = admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  databaseURL: "https://mhn-app.firebaseio.com"
});



var db = firebase.database();
var users = db.child('users');
var query = users.orderByChild('fcmToken');

console.log(users);
  

db.child不是函数

我遵循了Firebase教程中的确切语法:

https://www.youtube.com/watch?v=3WTQZV5-roY

看看 4:33 分钟,您会看到

enter image description here

我希望有人可以对此有所启发

1 个答案:

答案 0 :(得分:3)

我不知道您在哪里找到了这个示例(显然是从YouTube Firebase频道!??),但是child()方法是Reference的方法,而不是{{3 }}。

因此,您应该这样做:

var db = firebase.database();
var users = db.ref().child('users');
var query = users.orderByChild('fcmToken');

或直接:

var db = firebase.database();
var users = db.ref('users');
var query = users.orderByChild('fcmToken');