Skip to content

Can't using the findAndModify to update specific field. #308

@SittiphanSittisak

Description

@SittiphanSittisak

The result always be null from this code:

  Map<String, dynamic> data = await mongodb.dbCollection.findAndModify(
    update: [
      {'field A': 'data A'},
      {'field B': 'data B'},
    ],
    query: where.id(ObjectId.parse('Object Id')),
    returnNew: true,
  );

but it works with this code. But I don't want to replace the document:

  Map<String, dynamic> data = await mongodb.dbCollection.findAndModify(
    update: {'field A': 'data A', 'field B': 'data B'},
    query: where.id(ObjectId.parse('Object Id')),
    returnNew: true,
  );

I get an error Exception: Not implemented for ModifierBuilder({$set: {field A: data A}})
When I try using modify.set like this:

  Map<String, dynamic> data = await mongodb.dbCollection.findAndModify(
    update: [
      modify.set('field A', 'data A'),
      modify.set('field B', 'data B'),
    ],
    query: where.id(ObjectId.parse('Object Id')),
    returnNew: true,
  );

What do I mistake?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions