Closed SittiphanSittisak closed 1 year ago
You canno substitute the _id
field, once assigned it cannot be changed. You have to create a new record with the same data and the new key and delete the old one.
Hi @giorgiofran, I want to send data via an API with the Map that contains { '_id' : (data[i]['_id'] as ObjectId).$oid }
(the value type is String) not { '_id' : data[i]['_id'] }
(the value type is ObjectId). (Not change data in the database)
At the moment I must use a loop to change this. Is any way without using a loop?
List<Map<String, dynamic>> selectionList = await mongodb.selectionDbCollection
.find(where.fields(['value']))
.map((event) {
event['_id'] = (event['_id'] as ObjectId).$oid;
return event;
}).toList();
I'd do the same way you did.
Thank you @giorgiofran . This clear.
I want to replace the '_id' value (ObjectId) with the
ObjectId.$oid
. I am using:but this looks like not good practice. Are there any functions in
find()
to solve it?