Home > Blockchain >  type 'ObjectId' is not a subtype of type 'String' of 'value'
type 'ObjectId' is not a subtype of type 'String' of 'value'

Time:06-03

I am trying to insert a document into my Mongo Database using the package mongo_dart

  var db = await Db.create(MONGO_CONN_STRING);
  await db.open();
  var coll = db.collection('reports');
  await coll.insertOne({
    "username": "Tom",
    "action": "test",
    "dateTime": "today",
  });

Runtime error on line 4

Unhandled Exception: type 'ObjectId' is not a subtype of type 'String' of 'value'

Is it an issue with the package or is something wrong with my code?

CodePudding user response:

try this one

var db = await Db.create(MONGO_CONN_STRING);
  await db.open();
  var coll = db.collection('reports');
  await coll.insertOne({
    "username": "Tom",
    "action": "test",
    "dateTime": "today",
  }).toList();

CodePudding user response:

Are you using the latest version of the package?

I think your problem is related to this issue in the GitHub Repo of the package but it is closed at Jul 25, 2015.

  • Related