Is there a character limit for the string parameter used in the startAt() function of

I was just about to post this question on their github repository, but it looks like they prefer general inquiries to be asked here instead.

Is there a character limit for parameters when using startAt() to retrieve data from the firebase database?

I recently encountered an issue where it appears to be restricted to only 41 characters, but I haven't been able to find any documentation confirming this.

If indeed there is a limit, is there a way to extend it? (I need to filter values with up to 60 characters)

Although I can pass longer parameters, the database seems to only filter results based on the first 41 characters and ignores the rest of the value.

Just to note, I am using the JavaScript SDK in this case.

The dataset consists of values that are approximately 100 characters long, with the first 41 characters being identical in each one, differing at the tail end:

{
  "obj1": {"param": "abcdefghijklmnopqrstuvwxyz0123456789ABCDEF_0123456789ABCDEFabcdefghijklmnopqrstuvwxyz0123456789ABCDEF"},
  "obj2": {"param": "abcdefghijklmnopqrstuvwxyz0123456789ABCDEF_123456789ABCDEFabcdefghijklmnopqrstuvwxyz0123456789ABCDEF"},
  "obj3": {"param": "abcdefghijklmnopqrstuvwxyz0123456789ABCDEF_23456789ABCDEFabcdefghijklmnopqrstuvwxyz0123456789ABCDEF"},
  "obj4": {"param": "abcdefghijklmnopqrstuvwxyz0123456789ABCDEF_3456789ABCDEFabcdefghijklmnopqrstuvwxyz0123456789ABCDEF"},
  "obj5": {"param": "abcdefghijklmnopqrstuvwxyz0123456789ABCDEF_456789ABCDEFabcdefghijklmnopqrstuvwxyz0123456789ABCDEF"}
}

Currently, I need to retrieve "obj1" based on the value of the key "param," knowing only the first 60 characters of it (thus unable to use equalTo()):

var ref = firebase.database().ref("/some/data");

ref.orderByChild("param")
   .startAt("abcdefghijklmnopqrstuvwxyz0123456789ABCDEF_0123456789ABCDEFabc") <- this length is 60 characters
   .once("value")
   .then(function(snapshot) {
     snapshot.forEach(function(child) {
       console.log(child.key);
     });
   })

My expectation was to receive only one result, but the code above returns all records from the set instead.

Answer №1

It appears that there may be some confusion regarding the functionality of the startAt operation. It seems like you are attempting to filter strings that begin with a specific substring using startAt, but that is not how this function operates.

When you organize the children based on the value of the param property, Firebase arranges all children according to that parameter's value. Then, when you start at

abcdefghijklmnopqrstuvwxyz0123456789ABCDEF_0123456789ABCDEFabc
, it starts retrieving nodes from that point onward. In this scenario,
abcdefghijklmnopqrstuvwxyz0123456789ABCDEF_123456789ABCDEFabcdefghijklmnopqrstuvwxyz0123456789ABCDEF
comes after
abcdefghijklmnopqrstuvwxyz0123456789ABCDEF_0123456789ABCDEFabc
.

If you desire to retrieve the first child starting at a specific value, consider utilizing

.startAt(searchTerm).limitToFirst(1)
.

To obtain children starting with a particular value, employ a closed range with

startAt(searchTerm).endAt(searchTerm+"\uf8ff")
. The character \uf8ff represents the final Unicode character in this context.

Answer №2

I attempted to replicate this issue in both a JavaScript and Swift project, but was unsuccessful.

Here is the data I used:

{
  "key1" : "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
  "key2" : "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFZHIJKLMNOPQRSTUVWXYZ0123456789",
  "key3" : "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFHHIJKLMNOPQRSTUVWXYZ0123456789",
  "key4" : "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFIHIJKLMNOPQRSTUVWXYZ0123456789",
  "key5" : "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFJHIJKLMNOPQRSTUVWXYZ0123456789"
}

This is my JavaScript code:

var ref = firebase.database().ref("/51151783");

ref.orderByValue()
   .startAt("abcdefghijklmnopqrstuvwxyz0123456789ABCDEFI")
   .once("value")
   .then(function(snapshot) {
     snapshot.forEach(function(child) {
       console.log(child.key);
     });
   })

And here is my Swift code:

func searchForLongValue51151783() {
    let ref = Database.database().reference(withPath: "51151783")
    ref.queryOrderedByValue().queryStarting(atValue: "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFI").observeSingleEvent(of: .value, with: { (snapshot) in
            for child in snapshot.children {
                print((child as! DataSnapshot).key)
            }
    })
}

The result of the queries are:

key4

key5

key2

You can view the demonstration on jsbin: http://jsbin.com/lupebuwihu/edit?js,console.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Implementing class changes based on scroll events in JavaScript

const scrollList = document.getElementsByClassName('scrollList'); function scrollLeft() { scrollList.scrollLeft -= 50 } function scrollRight() { scrollList.scrollLeft += 50 } #scrollList { display: flex; overflow: auto; width: 10 ...

Dealing with the percentage sign in table names during data retrieval

When using React and Express to retrieve and store data in JSON format, what is the correct way to reference tables that have a percentage sign in their name? componentDidMount() { // Retrieve data from http://localhost:5000/citystats, sort by ID, t ...

Executing an automated process of adding items to the shopping cart using Python without the need to have a

Does anyone know of a way to automate the add-to-cart process using Python without the need for an open browser window? I've experimented with modules like mechanize, but they lack the ability to directly interact with web elements. Currently, I&apo ...

Determining the specific condition that failed in a series of condition checks within a TypeScript script

I am currently trying to determine which specific condition has failed in a set of multiple conditions. If one does fail, I want to identify it. What would be the best solution for achieving this? Here is the code snippet that I am using: const multiCondi ...

Unable to deliver an xlsx file from a Node.js (express) service that retrieves it from a S3 bucket, to be accessed by a browser application

After creating an xlsx file in Excel and manually uploading it from the desktop to AWS S3 via the console, I am now trying to add an endpoint to a Node.js express service. This endpoint should retrieve the file from S3 and pass it back to a JavaScript brow ...

What is the best way to integrate a bootstrap CSS stylesheet into my Express/Node.js project?

Currently, my approach involves using the following code to fetch my html file. app.get("/", function (request, response) { response.sendFile(__dirname + "/public_html/index.html"); }) The html file contains a form with method="post" and a submit button. ...

Decoding the values in an input field

Can anyone help me with identifying links, numbers, and text in WhatsApp and other app input boxes? I also want to be able to preview the page attached to a link and style these elements separately from other text. I am currently working on a project whe ...

Adding a dynamically generated dropdown button: Steps to trigger a delegated event

I am currently using bootstrap 3.3.7 in my project. On a particular page, there is a table with a dropdown button in one of the columns. I am dynamically adding rows to this table, and each new row also contains a dropdown button. However, these added butt ...

IE displaying "slow script" alert due to Knockout malfunction

Within my grid of observables and computed observables, the first row serves as a multiplier for all subsequent rows. Users can modify this percentage rate and Knockout automatically updates all relevant values accordingly. Additionally, I require a textbo ...

Validation is performed on the Bootstrap modal form, ensuring that the modal is only loaded after the

In order to provide a better understanding of my website's file structure, I would like to give an overview. The index.php file dynamically adds many pages to my website. Here is the code from index.php: <?php include ('pages/tillBody.php ...

Developing a Jquery solution for creating radio buttons layout

Looking to create a radio button functionality within different groups using multiple select. For Group A: If the user selects A1, then it should automatically deselect A2 and A3. If the user selects A2, then it should automatically deselect A1 and A3. I ...

How can I restrict validation to trigger only when a field loses focus?

Is there a way to validate the input tag for time format 00:00:00 after exiting the field, rather than during user typing? Any suggestions on how to accomplish this? <label for="operativeToTime">Operative to time</label> <input name ...

JavaScript not populating data in ASP TextBox or Input field

<asp:TextBox ID="DataBus" runat="server"></asp:TextBox> This is a text box element that is currently not being populated with any data from JavaScript. $("#DataBus").val('hi'); Even after trying the HTML code below, the issue persi ...

Perform a function within another function in Vue

I am dealing with two nested functions in Vue. The parent function needs to retrieve the value of an attribute, while the child function is responsible for using this attribute value to make an API call. How can I ensure that both parts are executed simult ...

Error: Attempting to access a property of an undefined object using method chaining

I encountered an error of property undefined with the code below. I'm not sure what's causing it. I checked by doing a console.log(navList) in the render and it does have a value. Even after adding if(!navList) return null, I still get the same e ...

Looking to replace a background image using javascript?

(apologies for any language mistakes) I have multiple divs with a common background image. I assigned them the same class and set the background image using CSS in style.css which worked perfectly fine. Now, I want to change the background image dynamical ...

Top method for integrating switchable pages into a Bootstrap single-page application

Currently, I am in the process of developing a straightforward web UI for an embedded platform. In terms of styling the layout, I am considering using bootstrap 4 as it appears to be a suitable option. The objective is to create a one-page application with ...

Unraveling the Perfect Jest Stack Trace

Currently, I am in the process of debugging some tests that were written with jest using typescript and it's causing quite a headache. Whenever a test or tested class runs Postgres SQL and encounters an error in the query, the stack trace provided is ...

Obtaining the contents of a request's body

const app = express() app.use(bodyParser()) router.get('/edaman', (req, res) => { console.log(req.body) axios.get(edamanUrl) .then(function (response) { const recipes = response.data.hits return res.status(200).jso ...

What is the distinction between declaring a variable as var $a=$() versus var a?

In some cases, in JQuery we assign a variable like var $a=$(), resembling the declaration of a function. I am curious to know if there is any difference if we simply define the variable as var a? ...