Search code examples
node.jsgoogle-bigquerygoogle-cloud-platformgoogle-cloud-functionsgoogle-api-nodejs-client

BigQuery cannot add data with nodejs API


I tried to use google-cloud-functions with BigQuery using the following cloud function example link. I didn't have any errors but the data didn't add to BigQuery.

BigQuery response is (status 200):

[ { "kind": "bigquery#tableDataInsertAllResponse" } ]

I tested locally using expressjs app with google service account but I got the same response.

Here is my code use in local:

    function saveLogBigQuery(req, res, status, errors=null){  
 const dataset = bigquery.dataset('logs_functions');  
 const table = dataset.table('testing');

      return table.insert([{
        name:'works!'   }]).then(function(data) {
        console.log("works!");
        console.log(JSON.stringify(data));
        res.send(data);   })
        .catch(function(err) {
          // An API error or partial failure occurred.
          console.log(JSON.stringify(err));
          res.send(err);
        }); }
       router2.get('/places', (req, res) => {   return saveLogBigQuery(req,res,200); });
       router2.listen(3000, function () {   console.log('Example app listening on port 3000!') });

And here is my local config:

const bigquery = require('@google-cloud/bigquery')({
  projectId: 'project-id',
  credentials: require('./service-account.json')
});

Any ideas, what is wrong?

EDIT:

RESPONSE: Probably was something with cache or refresh of page https://bigquery.cloud.google.com/table/project-id , now was the data :)


Solution

  • There's a known bug with using the table preview. You should query the table directly to see if there is data in it.