You're viewing the legacy docs. They are deprecated as of May 18, 2016.
These docs are for version 2.4.2 and below of the Javascript SDK. Go to our current docs, or see our Web migration guide.

Version 2.4.2Changelog

Firebase.set()

Write data to this database location. This will overwrite any data at this location and all child locations.

The effect of the write will be visible immediately and the corresponding events ('value', 'child_added', etc.) will be triggered. Synchronization of the data to the Firebase servers will also be started, and if provided, the onComplete callback will be called asynchronously after synchronization has finished.

Passing null for the new value is equivalent to calling remove(); all data at this location or any child location will be deleted.

set() will remove any priority stored at this location, so if priority is meant to be preserved, you should use setWithPriority() instead.

Note that modifying data with set() will cancel any pending transactions at that location, so extreme care should be taken if mixing set() and transaction() to modify the same data.

A single set() will generate a single "value" event at the location where the set() was performed.

var fredNameRef = new Firebase('https://docs-examples.firebaseio.com/samplechat/users/fred/name');

fredNameRef.child('first').set('Fred');
fredNameRef.child('last').set('Flintstone');
// We've written 'Fred' to the database location storing fred's first name,
// and 'Flintstone' to the location storing his last name
fredNameRef.set({ first: 'Fred', last: 'Flintstone' });
// Exact same effect as the previous example, except we've written
// fred's first and last name simultaneously
var onComplete = function(error) {
  if (error) {
    console.log('Synchronization failed');
  } else {
    console.log('Synchronization succeeded');
  }
};
fredNameRef.set({ first: 'Fred', last: 'Flintstone' }, onComplete);
// Same as the previous example, except we will also log a message
// when the data has finished synchronizing