why does it say "The getter 'fieldName' isn't defined for the type 'Map<String, dynamic>'" when I would have to return a fieldname.
import 'package:mongo_dart/mongo_dart.dart';
var db = Db("mongodb://127.0.0.1:27017/test");
await db.open();
var collection = db.collection('Users');
await collection.find().forEach(
(users) {
dbfieldName = users.fieldName; // This is where the problem occurs.
},
);
Thanks in advance.
The method
find
retrieves many documents, so anyusers
that you get is a document (in Map format). Now I have not clear what you want to do withfieldName
. If you want all field names for the documentusers
you can do:if you want the value of the field 'foo' you have to fetch it from the map: