Invalid document reference. Document references must have an even number of segments
I am querying a collection for documents using below code. Document names are same as device names. The device name is passed to the document from an API I am getting an error when a device name contains letter "/" like Motorola C380/C385.
I get an error
java.lang.IllegalArgumentException: Invalid document reference.
Document references must have an even number of segments, but
Mobiles/Motorola C380/C385 has 3
I know I am getting this error because FireStore considers the name C385 after slash as a collection inside a document. I want to know how to get rid of situations like this when a document name can contain a "/" should I check and remove this before inserting it into my collection or is there any better solution?
firebaseFirestore.collection("Mobiles").document(response.body().get(finalI).getDeviceName())
java android firebase google-cloud-firestore
add a comment |
I am querying a collection for documents using below code. Document names are same as device names. The device name is passed to the document from an API I am getting an error when a device name contains letter "/" like Motorola C380/C385.
I get an error
java.lang.IllegalArgumentException: Invalid document reference.
Document references must have an even number of segments, but
Mobiles/Motorola C380/C385 has 3
I know I am getting this error because FireStore considers the name C385 after slash as a collection inside a document. I want to know how to get rid of situations like this when a document name can contain a "/" should I check and remove this before inserting it into my collection or is there any better solution?
firebaseFirestore.collection("Mobiles").document(response.body().get(finalI).getDeviceName())
java android firebase google-cloud-firestore
add a comment |
I am querying a collection for documents using below code. Document names are same as device names. The device name is passed to the document from an API I am getting an error when a device name contains letter "/" like Motorola C380/C385.
I get an error
java.lang.IllegalArgumentException: Invalid document reference.
Document references must have an even number of segments, but
Mobiles/Motorola C380/C385 has 3
I know I am getting this error because FireStore considers the name C385 after slash as a collection inside a document. I want to know how to get rid of situations like this when a document name can contain a "/" should I check and remove this before inserting it into my collection or is there any better solution?
firebaseFirestore.collection("Mobiles").document(response.body().get(finalI).getDeviceName())
java android firebase google-cloud-firestore
I am querying a collection for documents using below code. Document names are same as device names. The device name is passed to the document from an API I am getting an error when a device name contains letter "/" like Motorola C380/C385.
I get an error
java.lang.IllegalArgumentException: Invalid document reference.
Document references must have an even number of segments, but
Mobiles/Motorola C380/C385 has 3
I know I am getting this error because FireStore considers the name C385 after slash as a collection inside a document. I want to know how to get rid of situations like this when a document name can contain a "/" should I check and remove this before inserting it into my collection or is there any better solution?
firebaseFirestore.collection("Mobiles").document(response.body().get(finalI).getDeviceName())
java android firebase google-cloud-firestore
java android firebase google-cloud-firestore
edited Nov 14 '18 at 11:28
walter
asked Nov 14 '18 at 11:16
walterwalter
96
96
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
The simplest method I can think of, is before you add the data to the database to find that forbidden /
symbol and replace it with an allowed one, let's say -
(minus).
String deviceName = response.body().get(finalI).getDeviceName().replaceAll("/", "-");
And then simply use in your reference like this:
firebaseFirestore.collection("Mobiles").document(deviceName);
Hi walter! Have you tried my solution above, does it work?
– Alex Mamo
Nov 15 '18 at 7:43
add a comment |
try this
response.body().get(finalI).getDeviceName().toString().replace("/","_")
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53298957%2finvalid-document-reference-document-references-must-have-an-even-number-of-segm%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
The simplest method I can think of, is before you add the data to the database to find that forbidden /
symbol and replace it with an allowed one, let's say -
(minus).
String deviceName = response.body().get(finalI).getDeviceName().replaceAll("/", "-");
And then simply use in your reference like this:
firebaseFirestore.collection("Mobiles").document(deviceName);
Hi walter! Have you tried my solution above, does it work?
– Alex Mamo
Nov 15 '18 at 7:43
add a comment |
The simplest method I can think of, is before you add the data to the database to find that forbidden /
symbol and replace it with an allowed one, let's say -
(minus).
String deviceName = response.body().get(finalI).getDeviceName().replaceAll("/", "-");
And then simply use in your reference like this:
firebaseFirestore.collection("Mobiles").document(deviceName);
Hi walter! Have you tried my solution above, does it work?
– Alex Mamo
Nov 15 '18 at 7:43
add a comment |
The simplest method I can think of, is before you add the data to the database to find that forbidden /
symbol and replace it with an allowed one, let's say -
(minus).
String deviceName = response.body().get(finalI).getDeviceName().replaceAll("/", "-");
And then simply use in your reference like this:
firebaseFirestore.collection("Mobiles").document(deviceName);
The simplest method I can think of, is before you add the data to the database to find that forbidden /
symbol and replace it with an allowed one, let's say -
(minus).
String deviceName = response.body().get(finalI).getDeviceName().replaceAll("/", "-");
And then simply use in your reference like this:
firebaseFirestore.collection("Mobiles").document(deviceName);
answered Nov 14 '18 at 11:36
Alex MamoAlex Mamo
42.5k82860
42.5k82860
Hi walter! Have you tried my solution above, does it work?
– Alex Mamo
Nov 15 '18 at 7:43
add a comment |
Hi walter! Have you tried my solution above, does it work?
– Alex Mamo
Nov 15 '18 at 7:43
Hi walter! Have you tried my solution above, does it work?
– Alex Mamo
Nov 15 '18 at 7:43
Hi walter! Have you tried my solution above, does it work?
– Alex Mamo
Nov 15 '18 at 7:43
add a comment |
try this
response.body().get(finalI).getDeviceName().toString().replace("/","_")
add a comment |
try this
response.body().get(finalI).getDeviceName().toString().replace("/","_")
add a comment |
try this
response.body().get(finalI).getDeviceName().toString().replace("/","_")
try this
response.body().get(finalI).getDeviceName().toString().replace("/","_")
edited Nov 14 '18 at 14:25
Frank van Puffelen
234k29380407
234k29380407
answered Nov 14 '18 at 11:33
Saravana kumarSaravana kumar
213
213
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53298957%2finvalid-document-reference-document-references-must-have-an-even-number-of-segm%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown