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.once()

Listens for exactly one event of the specified event type, and then stops listening. This is equivalent to calling on(), and then calling off() inside the callback function.

See on() for details on event types.

// Basic usage of .once() to read the data located at firebaseRef.
firebaseRef.once('value', function(dataSnapshot) {
  // handle read data.
});
// Provide a failureCallback to be notified when this
// callback is revoked due to security violations.
firebaseRef.once('value', function (dataSnapshot) {
  // code to handle new value
}, function (err) {
  // code to handle read error
});
// Provide a context to override "this" when callbacks are triggered.
firebaseRef.once('value', function (dataSnapshot) {
  // this.x is 1
}, {x: 1});