我对firestore非常满意,但是我想模块化我的应用程序,以便能够更轻松地在其中进行搜索。 在index.js中,我试图将对数据库的引用导出,但是它不起作用。
在index.js中:
admin.initializeApp({
credential: xxxxx,
databaseURL: xxxxxxx,
});
const db = admin.firestore();
module.exports.db = db;
在database.js中
const firestore = require("./index");
var refCity = firestore.collection("cities");
var refType = firestore.collection("type");
var refSaleType = firestore.collection("saleType");
module.exports = { refCity, refType, refSaleType };
但是我得到这个错误:
var refCity = firestore.db.collection("cities");
^
TypeError: Cannot read property 'collection' of undefined