这是我的编码,我们连接firebase数据库
var express = require('express')
var app = express()
app.listen(3000)
app.engine('html', require('ejs').renderFile)
app.use(express.static('public'))
var bodyParser = require('body-parser');
var sm = require('sitemap')
var firebase = require('firebase').initializeApp({
apiKey: "xx",
authDomain: "xx.firebaseapp.com",
databaseURL: "https://xx.firebaseio.com",
projectId: "xx",
storageBucket: "xx.appspot.com",
messagingSenderId: "xx"
});
我从firebase数据库查询数据
database = firebase.database();
var ref = database.ref('urls');
ref.on('value', gotData, errData);
function gotData(data){
console.log(data.val())
}
我得到如下结果
{ salmon:
{ count: 1,
last_res: 10,
url_site: 'salmon' },
'salmon-food':
{ count: 1,
last_res: 601,
url_site: 'salmon-food' } }
我需要将url_site添加到' pagex'只有last_res< 5
var sitemap = sm.createSitemap({
hostname: 'xxx.com',
cacheTime: 600000, // 600 sec - cache purge period
urls: [
{ url: '/pagex/'},
{ url: '/pagex/'},
{ url: '/pagex/'},
{ url: '/pagex/'}
]
});
谢谢:)
答案 0 :(得分:0)
您可以尝试此操作,假设您的firebase结果存储在变量ProjectC
-
result
这会给你一个像 -
这样的数组const urls = Object.keys(result)
.filter(key => result[key].last_res < 5)
.map(key => ({url: '/' + result[key].url_site + '/'}))
然后你可以使用它 -
[ { url: '/salmon/' }, { url: '/salmon-food/' } ]