-
Notifications
You must be signed in to change notification settings - Fork 376
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
FieldPath doesn't allow special characters, Firebase Console does #423
Comments
I found a few problems with this issue:
|
The way to do what you want is to pass FieldPaths and values as separate arguments to the Here's how I did it: async function main() {
const albums = db.collection('albums');
const album = albums.doc();
await album.set({'title': 'Foo'});
await album.update(new FieldPath('tags', '[Bonus] Download'), true);
const snap = await album.get();
console.log(snap.id, snap.data());
}; Running this I got:
What's going on here is that if you pass an object literal to the Note that you can side-step this issue entirely by using Firestore's (relatively recent) support for array queries and operations. In this case you'd take the tag out of the field path, and make it an array value. The code to the above looks like this: async function main() {
const albums = db.collection('albums');
const album = albums.doc();
await album.set({'title': 'Foo'});
await album.update({
'tags': FieldValue.arrayUnion('[Bonus] Download')
});
const snap = await album.get();
console.log(snap.id, snap.data());
}; The output looks like this:
|
@wilhuff Do you know how I would do this with multiple such field paths, i.e. |
If you want to make multiple updates that aren't known ahead of time, use an array and then spread it into the call: const updates = [
new FieldPath('tags', '[Bonus] Download'), true,
new FieldPath('other', 'path'), "foo",
];
await album.update(...updates); |
@wilhuff Thank you for your quick reply! It worked! 💯 |
When trying to update a nested field, I get the following error:
But within the Firebase Console map keys can actually contain these special characters.
The error is the same, no matter if I use
new FieldPath( 'tags', '[Bonus] Download' )
or just build the update object myself like:I think I read somewhere in the documentation that I should escape paths with special charcters in backticks, but it still throws the same error.
Operating System version: Cloud Functions Node 8.14.0
Firebase SDK version: 6.3.0
Firebase Product: Firestore
The text was updated successfully, but these errors were encountered: