Can I have multiple unique field names?

Yes, you can specify multiple field names as part of unique_by as long as they are string, date or datetime fields and have unique identifiers.

Example

Here’s an example using Node.

var API_KEY = 'your_api_key';

var gb = require('geckoboard')(
  API_KEY
);

gb.datasets.findOrCreate(
  {
    id: 'sales.by_day',
    fields: {
      quantity: {
        type: 'number',
        name: 'Number of sales'
      },
      gross: {
        type: 'money',
        name: 'Gross value of sales',
        currency_code: "USD"
      },
      date: {
        type: 'date',
        name: 'Date'
      },
      name: {
        type: 'string',
        name: 'Name'
      }
    },
    "unique_by": ["date", "name"]
  },
  function (err, dataset) {
    if (err) {
      console.error(err);
      return;
    }

    dataset.put(
      [
        { date: '2016-01-01', quantity: 819, gross: 2457000, name: "one" },
        { date: '2016-01-02', quantity: 409, gross: 1227000, name: "two" },
        { date: '2016-01-02', quantity: 415, gross: 1229523, name: "two" },
        { date: '2016-01-03', quantity: 164, gross: 492000, name: "three" }
      ],
      function (err) {
        if (err) {
          console.error(err);
          return;
        }

        console.log('Dataset created and data added');
      }
    );
  }
);

The dataset, when checked, contains only 3 rows, despite sending 4. This is because one counts as a duplicate under those conditions. Only the later one is kept.

Was this article helpful?

Awesome! 👍 Thanks so much for your feedback!

Sorry about that! Start a conversation now.

We're ready to help, 24 hours a day, 5 days a week

Get support
  • Fernanda Customer Success Avatar

    Megan

    USA
  • Hariharan Customer Success Avatar

    Hariharan

    India
  • Fernanda Customer Success Avatar

    Yasmin

    Spain
  • Luis Customer Success Avatar

    Luis

    UK
  • Richard Customer Success Avatar

    Richard

    UK
  • Fernanda Customer Success Avatar

    Fernanda

    Brazil
  • Heather Customer Success Avatar

    Heather

    USA