firebase / flutterfire

🔥 A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.68k stars 3.97k forks source link

[cloud_firestore] Nested arrays are not supported #1637

Closed AttalliAyoub closed 4 years ago

AttalliAyoub commented 4 years ago

Describe the bug

can't query nested array in firestore

i was trying to query this:

_db.collection('chats')
    .where('owners', whereIn: [[_me, _he], [ _he ,_me]])
    .orderBy('createdAt', descending: true)
    .limit(2)

but i I've got this bug report:

E/flutter (13152): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(error, Invalid data. Nested arrays are not supported, null)
E/flutter (13152): #0      StandardMethodCodec.decodeEnvelope 
package:flutter/…/services/message_codecs.dart:569
E/flutter (13152): #1      MethodChannel.invokeMethod 
package:flutter/…/services/platform_channel.dart:321
E/flutter (13152): <asynchronous suspension>
E/flutter (13152): #2      Query.snapshots.<anonymous closure> 
package:cloud_firestore/src/query.dart:61
E/flutter (13152): #3      _runGuarded  (dart:async/stream_controller.dart:807:24)
E/flutter (13152): #4      _BroadcastStreamController._subscribe  (dart:async/broadcast_stream_controller.dart:215:7)
E/flutter (13152): #5      _ControllerStream._createSubscription  (dart:async/stream_controller.dart:820:19)
E/flutter (13152): #6      _StreamImpl.listen  (dart:async/stream_impl.dart:474:9)
E/flutter (13152): #7      new _ForwardingStreamSubscription  (dart:async/stream_pipe.dart:125:10)
E/flutter (13152): #8      _ForwardingStream._createSubscription  (dart:async/stream_pipe.dart:93:16)
E/flutter (13152): #9      _ForwardingStream.listen  (dart:async/stream_pipe.dart:88:12)

To Reproduce just query this:

_db.collection('chats')
    .where('owners', whereIn: [[_me, _he], [ _he ,_me]])
    .orderBy('createdAt', descending: true)
    .limit(2)

Expected behavior this code is working on the web and i'm using it my my angular app. i'll get the chat document.

Additional context thanks

AttalliAyoub commented 4 years ago

also i'm asking if there is a documentation for c++ method channel

iapicca commented 4 years ago

Hi @phoelapyae69 can you please provide your updated flutter doctor -v and your flutter run --verbose? Thank you

If you are looking for calling functions from c++ you may want to look into this docs

trunghvbk commented 4 years ago

Hi, I'm encountering the same issue here. Just call the query final querySnapshot = await _firestore.collection(FirestoreCollection.chat).where('emails', whereIn: [[widget.user.email, widget.friend]]) .getDocuments();

Note that: It's happening on android emulator and working fine on iOS simulator. Thank you!

flutter doctor -v :

Flutter (Channel stable, v1.12.13+hotfix.9, on Mac OS X 10.15.4 19E287,
    locale en-VN)
    • Flutter version 1.12.13+hotfix.9 at /Users/trunghvbk/Code/tools/flutter
    • Framework revision f139b11009 (2 weeks ago), 2020-03-30 13:57:30 -0700
    • Engine revision af51afceb8
    • Dart version 2.7.2

[!] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at /Users/trunghvbk/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling
      support)
    • Platform android-29, build-tools 29.0.2
    • Java binary at: /Applications/Android
      Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      1.8.0_212-release-1586-b4-5784211)
    ! Some Android licenses not accepted.  To resolve this, run: flutter doctor
      --android-licenses

[✓] Xcode - develop for iOS and macOS (Xcode 11.4)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.4, Build version 11E146
    • CocoaPods version 1.8.4

[✓] Android Studio (version 3.6)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 45.1.1
    • Dart plugin version 192.7761
    • Java version OpenJDK Runtime Environment (build
      1.8.0_212-release-1586-b4-5784211)

[✓] VS Code (version 1.44.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.9.1

[✓] Connected device (1 available)
    • Android SDK built for x86 • emulator-5554 • android-x86 • Android 10 (API
      29) (emulator)

flutter run --verbose :

E/MethodChannel#plugins.flutter.io/cloud_firestore( 6104): Failed to
handle method call
[        ] E/MethodChannel#plugins.flutter.io/cloud_firestore( 6104):
java.lang.IllegalArgumentException: Invalid data. Nested arrays are not
supported
[        ] E/MethodChannel#plugins.flutter.io/cloud_firestore( 6104):   at
com.google.firebase.firestore.core.UserData$ParseContext.createError(com.google.
firebase:firebase-firestore@@21.3.0:291)
[        ] E/MethodChannel#plugins.flutter.io/cloud_firestore( 6104):   at
com.google.firebase.firestore.UserDataConverter.parseData(com.google.firebase:fi
rebase-firestore@@21.3.0:270)
[        ] E/MethodChannel#plugins.flutter.io/cloud_firestore( 6104):   at
com.google.firebase.firestore.UserDataConverter.parseList(com.google.firebase:fi
rebase-firestore@@21.3.0:307)
[        ] E/MethodChannel#plugins.flutter.io/cloud_firestore( 6104):   at
com.google.firebase.firestore.UserDataConverter.parseData(com.google.firebase:fi
rebase-firestore@@21.3.0:272)
[        ] E/MethodChannel#plugins.flutter.io/cloud_firestore( 6104):   at
com.google.firebase.firestore.UserDataConverter.convertAndParseFieldData(com.goo
gle.firebase:firebase-firestore@@21.3.0:211)
[        ] E/MethodChannel#plugins.flutter.io/cloud_firestore( 6104):   at
com.google.firebase.firestore.UserDataConverter.parseQueryValue(com.google.fireb
ase:firebase-firestore@@21.3.0:200)
[        ] E/MethodChannel#plugins.flutter.io/cloud_firestore( 6104):   at
com.google.firebase.firestore.Query.whereHelper(com.google.firebase:firebase-fir
estore@@21.3.0:351)
[        ] E/MethodChannel#plugins.flutter.io/cloud_firestore( 6104):   at
com.google.firebase.firestore.Query.whereIn(com.google.firebase:firebase-firesto
re@@21.3.0:298)
[        ] E/MethodChannel#plugins.flutter.io/cloud_firestore( 6104):   at
io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin.getQuery(CloudFi
restorePlugin.java:306)
[        ] E/MethodChannel#plugins.flutter.io/cloud_firestore( 6104):   at
io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin.onMethodCall(Clo
udFirestorePlugin.java:797)
[        ] E/MethodChannel#plugins.flutter.io/cloud_firestore( 6104):   at
io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(Metho
dChannel.java:231)
[        ] E/MethodChannel#plugins.flutter.io/cloud_firestore( 6104):   at
io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMesseng
er.java:93)
[        ] E/MethodChannel#plugins.flutter.io/cloud_firestore( 6104):   at
io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:642
)
[        ] E/MethodChannel#plugins.flutter.io/cloud_firestore( 6104):   at
android.os.MessageQueue.nativePollOnce(Native Method)
[        ] E/MethodChannel#plugins.flutter.io/cloud_firestore( 6104):   at
android.os.MessageQueue.next(MessageQueue.java:336)
[        ] E/MethodChannel#plugins.flutter.io/cloud_firestore( 6104):   at
android.os.Looper.loop(Looper.java:174)
[        ] E/MethodChannel#plugins.flutter.io/cloud_firestore( 6104):   at
android.app.ActivityThread.main(ActivityThread.java:7356)
[        ] E/MethodChannel#plugins.flutter.io/cloud_firestore( 6104):   at
java.lang.reflect.Method.invoke(Native Method)
[        ] E/MethodChannel#plugins.flutter.io/cloud_firestore( 6104):   at
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492
)
[        ] E/MethodChannel#plugins.flutter.io/cloud_firestore( 6104):   at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
[ +148 ms] E/flutter ( 6104): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)]
Unhandled Exception: PlatformException(error, Invalid data. Nested arrays are
not supported, null)
[        ] E/flutter ( 6104): #0      StandardMethodCodec.decodeEnvelope
(package:flutter/src/services/message_codecs.dart:569:7)
[        ] E/flutter ( 6104): #1      MethodChannel.invokeMethod
(package:flutter/src/services/platform_channel.dart:321:33)
[        ] E/flutter ( 6104): <asynchronous suspension>
[        ] E/flutter ( 6104): #2      MethodChannel.invokeMapMethod
(package:flutter/src/services/platform_channel.dart:349:48)
[        ] E/flutter ( 6104): #3      MethodChannelQuery.getDocuments
(package:cloud_firestore_platform_interface/src/method_channel/method_channel_qu
ery.dart:87:46)
[        ] E/flutter ( 6104): #4      Query.getDocuments
(package:cloud_firestore/src/query.dart:37:34)
[        ] E/flutter ( 6104): #5      _MessagePageState._loadDocumentID
(package:studentvn/pages/elements/message_page.dart:55:10)
[        ] E/flutter ( 6104): #6      _MessagePageState.initState
(package:studentvn/pages/elements/message_page.dart:50:5)
[        ] E/flutter ( 6104): #7      StatefulElement._firstBuild
(package:flutter/src/widgets/framework.dart:4355:58)
[        ] E/flutter ( 6104): #8      ComponentElement.mount
(package:flutter/src/widgets/framework.dart:4201:5)
[        ] E/flutter ( 6104): #9      Element.inflateWidget
(package:flutter/src/widgets/framework.dart:3194:14)
[        ] E/flutter ( 6104): #10     Element.updateChild
(package:flutter/src/widgets/framework.dart:2988:12)
[        ] E/flutter ( 6104): #11     SingleChildRenderObjectElement.mount
(package:flutter/src/widgets/framework.dart:5445:14)
[        ] E/flutter ( 6104): #12     Element.inflateWidget
(package:flutter/src/widgets/framework.dart:3194:14)
[        ] E/flutter ( 6104): #13     Element.updateChild
(package:flutter/src/widgets/framework.dart:2988:12)
[        ] E/flutter ( 6104): #14     ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:4243:16)
[        ] E/flutter ( 6104): #15     Element.rebuild
(package:flutter/src/widgets/framework.dart:3947:5)
[        ] E/flutter ( 6104): #16     ComponentElement._firstBuild
(package:flutter/src/widgets/framework.dart:4206:5)
[        ] E/flutter ( 6104): #17     ComponentElement.mount
(package:flutter/src/widgets/framework.dart:4201:5)
[        ] E/flutter ( 6104): #18     Element.inflateWidget
(package:flutter/src/widgets/framework.dart:3194:14)
[        ] E/flutter ( 6104): #19     Element.updateChild
(package:flutter/src/widgets/framework.dart:2988:12)
[        ] E/flutter ( 6104): #20     SingleChildRenderObjectElement.mount
(package:flutter/src/widgets/framework.dart:5445:14)
[        ] E/flutter ( 6104): #21     Element.inflateWidget
(package:flutter/src/widgets/framework.dart:3194:14)
[        ] E/flutter ( 6104): #22     Element.updateChild
(package:flutter/src/widgets/framework.dart:2988:12)
[        ] E/flutter ( 6104): #23     SingleChildRenderObjectElement.mount
(package:flutter/src/widgets/framework.dart:5445:14)
[        ] E/flutter ( 6104): #24     Element.inflateWidget
(package:flutter/src/widgets/framework.dart:3194:14)
[        ] E/flutter ( 6104): #25     Element.updateChild
(package:flutter/src/widgets/framework.dart:2988:12)
[        ] E/flutter ( 6104): #26     ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:4243:16)
[        ] E/flutter ( 6104): #27     Element.rebuild
(package:flutter/src/widgets/framework.dart:3947:5)
[        ] E/flutter ( 6104): #28     ComponentElement._firstBuild
(package:flutter/src/widgets/framework.dart:4206:5)
[        ] E/flutter ( 6104): #29     StatefulElement._firstBuild
(package:flutter/src/widgets/framework.dart:4381:11)
[        ] E/flutter ( 6104): #30     ComponentElement.mount
(package:flutter/src/widgets/framework.dart:4201:5)
[        ] E/flutter ( 6104): #31     Element.inflateWidget
(package:flutter/src/widgets/framework.dart:3194:14)
[        ] E/flutter ( 6104): #32     Element.updateChild
(package:flutter/src/widgets/framework.dart:2988:12)
[        ] E/flutter ( 6104): #33     SingleChildRenderObjectElement.mount
(package:flutter/src/widgets/framework.dart:5445:14)
[        ] E/flutter ( 6104): #34     Element.inflateWidget
(package:flutter/src/widgets/framework.dart:3194:14)
[        ] E/flutter ( 6104): #35     Element.updateChild
(package:flutter/src/widgets/framework.dart:2988:12)
[        ] E/flutter ( 6104): #36     SingleChildRenderObjectElement.mount
(package:flutter/src/widgets/framework.dart:5445:14)
[        ] E/flutter ( 6104): #37     Element.inflateWidget
(package:flutter/src/widgets/framework.dart:3194:14)
[        ] E/flutter ( 6104): #38     Element.updateChild
(package:flutter/src/widgets/framework.dart:2988:12)
[        ] E/flutter ( 6104): #39     ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:4243:16)
[        ] E/flutter ( 6104): #40     Element.rebuild
(package:flutter/src/widgets/framework.dart:3947:5)
[        ] E/flutter ( 6104): #41     ComponentElement._firstBuild
(package:flutter/src/widgets/framework.dart:4206:5)
[        ] E/flutter ( 6104): #42     StatefulElement._firstBuild
(package:flutter/src/widgets/framework.dart:4381:11)
[        ] E/flutter ( 6104): #43     ComponentElement.mount
(package:flutter/src/widgets/framework.dart:4201:5)
[        ] E/flutter ( 6104): #44     Element
jcamilorm902 commented 4 years ago

I have the same issue.

It's happening on android, but working fine on iOS.

flutter doctor -v:

[✓] Flutter (Channel stable, v1.17.0, on Mac OS X 10.15.4 19E287, locale es-419)
    • Flutter version 1.17.0 at ~/Applications/flutter
    • Framework revision e6b34c2b5c (5 days ago), 2020-05-02 11:39:18 -0700
    • Engine revision 540786dd51
    • Dart version 2.8.1

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    • Android SDK at ~/Library/Android/sdk
    • Platform android-29, build-tools 29.0.3
    • ANDROID_HOME = ~/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.4.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.4.1, Build version 11E503a
    • CocoaPods version 1.9.1

[✓] Android Studio (version 3.6)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 45.1.1
    • Dart plugin version 192.7761
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)

[✓] VS Code (version 1.44.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.10.1

[!] Connected device
    ! No devices available

! Doctor found issues in 1 category.

The exception generated in android plugin:

E/MethodChannel#plugins.flutter.io/cloud_firestore(19771): Failed to handle method call
E/MethodChannel#plugins.flutter.io/cloud_firestore(19771): java.lang.IllegalArgumentException: Invalid data. Nested arrays are not supported
E/MethodChannel#plugins.flutter.io/cloud_firestore(19771):  at com.google.firebase.firestore.core.UserData$ParseContext.createError(com.google.firebase:firebase-firestore@@21.3.0:291)
E/MethodChannel#plugins.flutter.io/cloud_firestore(19771):  at com.google.firebase.firestore.UserDataConverter.parseData(com.google.firebase:firebase-firestore@@21.3.0:270)
E/MethodChannel#plugins.flutter.io/cloud_firestore(19771):  at com.google.firebase.firestore.UserDataConverter.parseList(com.google.firebase:firebase-firestore@@21.3.0:307)
E/MethodChannel#plugins.flutter.io/cloud_firestore(19771):  at com.google.firebase.firestore.UserDataConverter.parseData(com.google.firebase:firebase-firestore@@21.3.0:272)
E/MethodChannel#plugins.flutter.io/cloud_firestore(19771):  at com.google.firebase.firestore.UserDataConverter.convertAndParseFieldData(com.google.firebase:firebase-firestore@@21.3.0:211)
E/MethodChannel#plugins.flutter.io/cloud_firestore(19771):  at com.google.firebase.firestore.UserDataConverter.parseQueryValue(com.google.firebase:firebase-firestore@@21.3.0:200)
E/MethodChannel#plugins.flutter.io/cloud_firestore(19771):  at com.google.firebase.firestore.Query.whereHelper(com.google.firebase:firebase-firestore@@21.3.0:351)
E/MethodChannel#plugins.flutter.io/cloud_firestore(19771):  at com.google.firebase.firestore.Query.whereIn(com.google.firebase:firebase-firestore@@21.3.0:298)
E/MethodChannel#plugins.flutter.io/cloud_firestore(19771):  at io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin.getQuery(CloudFirestorePlugin.java:311)
E/MethodChannel#plugins.flutter.io/cloud_firestore(19771):  at io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin.onMethodCall(CloudFirestorePlugin.java:841)
E/MethodChannel#plugins.flutter.io/cloud_firestore(19771):  at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:226)
E/MethodChannel#plugins.flutter.io/cloud_firestore(19771):  at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
E/MethodChannel#plugins.flutter.io/cloud_firestore(19771):  at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:631)
E/MethodChannel#plugins.flutter.io/cloud_firestore(19771):  at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#plugins.flutter.io/cloud_firestore(19771):  at android.os.MessageQueue.next(MessageQueue.java:336)
E/MethodChannel#plugins.flutter.io/cloud_firestore(19771):  at android.os.Looper.loop(Looper.java:174)
E/MethodChannel#plugins.flutter.io/cloud_firestore(19771):  at android.app.ActivityThread.main(ActivityThread.java:7356)
E/MethodChannel#plugins.flutter.io/cloud_firestore(19771):  at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#plugins.flutter.io/cloud_firestore(19771):  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
E/MethodChannel#plugins.flutter.io/cloud_firestore(19771):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
E/flutter (19771): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(error, Invalid data. Nested arrays are not supported, null)
Ehesp commented 4 years ago

As the error messages explain, nested arrays are not supported in Firestore so the query is not valid.

jcamilorm902 commented 4 years ago

@Ehesp These kind of queries should be supported by firebase android plugin because of this Google documentation:

https://firebase.google.com/docs/firestore/query-data/queries#in_and_array-contains-any

You can use an array value as a comparison value for in, but unlike array-contains-any, the clause matches for an exact match of array length, order, and values. For example: citiesRef.where('region', 'in', [['west_coast', 'east_coast']]);

that section gives an example for Java Android, Kotlin, Java that should be supported by this flutter plugin:

CollectionReference citiesRef = db.collection("cities");

Query query =
    citiesRef.whereIn(
        "regions", Arrays.asList(Arrays.asList("west_coast"), Arrays.asList("east_coast")));

In iOS plugin section this is supported. It should work in the same way in both platforms.

Nested arrays must be supported in these kind of queries!

Ehesp commented 4 years ago

Oh yeah, let me reopen and take a look.

Ehesp commented 4 years ago

Hi this is now fixed via https://github.com/FirebaseExtended/flutterfire/pull/2913