Home > Net >  Error: [cloud_firestore/unknown] Use FieldPath.of() for field names containing '~*/[]'
Error: [cloud_firestore/unknown] Use FieldPath.of() for field names containing '~*/[]'

Time:06-15

this is my first time seeing this error, but i am kind of confused. I want to update a collection and i keep getting this error,

[cloud_firestore/unknown] Use FieldPath.of() for field names containing '~*/[]'.

here is the fun that give that error.

Future<bool> addStudentDetails(
  String? about,
  List? skills,
  List? workExperience,
  List? certificate,
  String? level,
  List? discipline,
  bool campusCheck,
) async {
  try {
    await firestore.collection('/users').doc(auth.currentUser?.uid).update({
      'About': about ?? '',
      'skills': skills ?? [],
      'discipline': discipline ?? [],
      'compus/not': campusCheck ? "Online" : "Campus",
      'workExperience': workExperience ?? [],
      'certificate': certificate ?? [],
      'level': level ?? '',
      'done': true
    });
    return true;
  } catch (e) {
    print('========> $e');
    return false;
  }
}

CodePudding user response:

Mohamed has it correct in their comment, this error occurs because you have a slash in the field name here:

'compus/not': campusCheck ? "Online" : "Campus",

If you want the literal slash to be present in the field name, use FieldPath to define it:

FieldPath('compus/not'): campusCheck ? "Online" : "Campus",

If instead you want to use have a nested not field under the top-level compus field, use a dot to separate the two:

'compus.not': campusCheck ? "Online" : "Campus",
  • Related