Firestore entering text with a linebreak in the Console UI
Asked Answered
L

2

6

I can't figure out how to enter a string with a line break in the Firestore web UI. The JavaScript SDK works fine and preserves reading/writing of newlines, but I need to edit some data manually during development, and nothing I'm trying in the UI is working.

I've tried copying and pasting firstline\nsecondline, firstline\\nsecondline, and copying the string from a document with two actual newline characters

firstline

second line

I've also tried copying and pasting a unicode linefeed in the center of the string.

Is there a way to enter a string with a newline in the Console UI that I'm missing, or no?

edit: There's a related question here, but it doesn't address how to enter a string with newlines using the console, which is what I'm trying to do.

Lessor answered 5/10, 2022 at 21:39 Comment(6)
Does this answer your question? Does Cloud Firestore save strings with newline \n characters (multiline)?Madian
@RobertG no. That's about storing newlines with the API, which works fine (although that question also mentions that the console doesn't display newlines, which I have filed a firebase bug for). My question is about how to get a string with newlines into Firestore using the UI/Console, which I can't figure out.Lessor
Hello, I am stucking in the same issue, did you find anything? I tried copy paste from different text editors with no success!Azucenaazure
@MarkNugromentry there isn't any way currently. It's possible a client-side patch could be made with an extension, it's possible not, depending on the details of how it's implemented. While I'm not happy with this situation, Doug's answer is correct in that it's not built for this—he's almost always correct about Firebase.Lessor
You could write a small tool to write multiline strings to firebase as a small webapp or local CLI or something, plenty of options depending on your usecase. It's true that in general you shouldn't be directly mutating the DB, but it's useful for some edge conditions, and I wish they supported it better.Lessor
Thanks, I will add like a small admin panel anyway to controll the whole Firebastore staff.Azucenaazure
U
4

The console was not built for this use case. This applies to both Firestore and Realtime Database that came before it.

The console is primarily a debugging tool meant to give quick and easy access during development. It's not meant to be a primary interface for regular or administrative use. I suspect that the creators of the console intended for developers to build their own interfaces (admin web site, or CLI scripts) to meet specific needs like this. You are free to contact Firebase support to file a feature request if this is very important to you, but in this case I wouldn't get my hopes up.

Underwood answered 6/10, 2022 at 12:23 Comment(4)
I appreciate the answer, but that's quite disappointing, and, honestly, strange. It seems like supporting this would be quite easy. I'm not looking for a primary interface for production, but currently am setting test data that I'm consuming in the frontend, and don't have the time to build a producer/form for the content yet. I suppose I could write a quite CLI tool to write to the collection, or upload a json, but it's really strange that it allows me to write strings and just doesn't support newlines in any way. I would consider that a fairly large bug.Lessor
It's only a bug if it's not working as intended. I suspect that it is WAI in this case, and changing the UI to support newlines (both entered and displayed) was found to be problematic in some way, especially for strings that can get very long. If support is not helpful, you can also post to firebase-talk where staff is active. groups.google.com/g/firebase-talkUnderwood
Calling it a bug vs WAI is intended is mainly semantics, I think some design decisions can be effectively buggy. I really don't buy that it's problematic to implement though-- if very long strings are an issue, a limit could be easily added. But basic multi-line input and viewing is really easy. I just added white-space: pre-wrap to the span rendering text in console using the inspector, and I can see it with multiple lines (though I haven't verified the UI isn't stripping newlines when they load). Multi-line text input isn't a hard problem.Lessor
The only thing I can think of that makes this make sense is that Firebase is specifically trying to discourage console usage, but this seems like a really weird way to do that. (I know this isn't your fault, and I appreciate your answer. It's just frustrating. Overall though I find Firebase great to work with!)Lessor
P
2

As other users have stated, the console does not currently support this.

If you are willing to use a command line script, this will do the job:
https://gist.github.com/jakes-space/a01bc373a30e72c3736b77e5c2c23a84
It reads the doc at the given reference, opens its JSON in an editor, and writes the new version. Newline characters should be written as \n, not \\n.

(Disclaimers: I am the author. Please carefully check your changes before writing them.)

Photofluorography answered 6/9, 2023 at 20:11 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.