我可以控制将对象推送到 Firebase 阵列时生成的唯一 key/ID 吗?

Can I control the unique key/ID that gets generated when I push an object to Firebase Array?

我正在使用 AngularFire $add() 方法,该方法在后台调用 push(),将子对象添加到父对象。

Firebase documentation 表示 push() 方法:

Generates a new child location using a unique key and returns a Firebase reference to it.

我想控制为我推送的对象生成的唯一键或 ID。就像我想为随机 ID 添加一个常量前缀然后保存它。可能吗?

调用push()是纯客户端操作。所以你可以:

var newRef = ref.push();
var newKey = newRef.key();
var realRef = ref.child("myPrefix_"+newKey);
realRef.set({ title: 'tadaaa', body: 'New child with a push ID and a custom prefix' });