Android Question Query Firebase RealTimeDatabase (Select in clause) -Solved

virpalacios

Active Member
Licensed User
Longtime User
Hi everyone, I would like to have your opinion about an issue with Firebase Database, I already query the table "ordenes" using "=" operator, however I would like to use the "in" operator, I checked documentation, it says it is posible, I also make some check using the Firebase console. I got stuck in preparing the array parametr for the query, here is my code, I tried to create an array but it is not ok. At the end I included the google documentation.

Thanks in advance for your help

Subroutine for queri:
Sub verificar_pedido_globe_array
    gs_buscar_coleccion = "ordenes"
    Dim mapa As Map
    mapa.Initialize
    Dim data As List
    data.Initialize
    data.Add(CreateMap("collectionId":"ordenes"))
 
    Dim mapafiltro As Map
    mapafiltro.Initialize
    mapafiltro.Put("field",CreateMap("fieldPath":"NO_PEDIDO"))  ' name field
    mapafiltro.Put("op","in") 'Operator In'
    ' I got a error message about malformed Json, I tried this way, but it is wrong,
    mapafiltro.Put("value",Array(CreateMap("stringValue":"9364E7CE"),CreateMap("stringValue":"9364E7CE")))
    mapa.Put("from",data)
    mapa.Put("where",CreateMap("fieldFilter":mapafiltro))
    query (mapa)
End Sub
1740204873356.png

in operator
1740204931213.png
 
Last edited:

virpalacios

Active Member
Licensed User
Longtime User
Hi, after several and many tries, got the answer, I am going to explain with code, whoever need it can enjoy it, this is a follow up from previous jobs from
@Paolodc and @gregorio_adrian_gimenez without their efforts this code couldn't be posible. Best Regards

Subrutine for validating status code from firebase using order_number (no_pedido):
Sub verificar_pedido_globe_array
    gs_buscar_coleccion = "ordenes" 'Purchase orders collection in firebase
    Dim lista_ordenes As List
    Dim mapa As Map
    mapa.Initialize
    Dim data As List
    data.Initialize
    data.Add(CreateMap("collectionId":"ordenes"))   'Declare collection id
    lista_ordenes.Initialize  'List for purchase order number to be checked
    lista_ordenes.Add(CreateMap("stringValue": "9364E7CE")) ' Add an item to be validated - Check each element is a map
    lista_ordenes.Add(CreateMap("stringValue": "9364E7CF")) ' Add a second item to be validades - these are order numbers
    Dim mapafiltro As Map
    mapafiltro.Initialize
    mapafiltro.Put("field",CreateMap("fieldPath":"NO_PEDIDO"))  ' set field name for searching
    mapafiltro.Put("op","IN") 'For select In Style use "IN" method
    mapafiltro.Put("value",CreateMap("arrayValue":CreateMap("values":lista_ordenes))) ' Add criteria, check it is a array inside a map - be carefull with value and values in this sentence
    mapa.Put("from",data)
    mapa.Put("where",CreateMap("fieldFilter":mapafiltro))
    query (mapa) ' Place Firebase request
End Sub

If you have any additional question about this code be free to ask

Best Regards from Panama 🇵🇦


👍😄
 
Upvote 0
Top