Invalid function call request, no function was specified :: db.collection.insertMany

Hi. I am trying to call an insertMany call using the app.currentUser.mongoClient as specified in the docs. However when i try to insert a document I get either of the following error from attempting to insert these documents:

const asset: AssetSchema = {
          _id: {
            $oid: new BSON.ObjectId().toString(),
          owner: {
            $oid: new BSON.ObjectId(user._id).toString(),
          // _id: new BSON.ObjectId(),
          // owner: new BSON.ObjectId(user._id),
          size: s3Object.size,
          synced: false,
          tags: [],
          thumbnail: s3Object.thumbnail,
          dateCreated: {
            $date: new Date(),

await db.collection<AssetSchema>("Asset").insertMany(syncingAssets);

Error 1: If i use the regular _id: new BSON.ObjectId() I get the following error:
SchemaValidationFailedWrite Error as it sends an empty object and thus get type mismatch.

Error 2: If i use the { $oid: … } it send it fine but then i get the following error:
InvalidParameter Error: invalid function call request, no function was specified

Can’t figure out why BSON.ObjecId creates a type mismatch nor why I get the InvalidParameter Error when i can successfully call functions in my react native app

realm: 12.0.0-browser.2
@realm/react: 0.6.2

I do not know react or realm so I might be completely on the wrong track. But you could check the following.

For the field owner, the value of user._id is probably already an object id. So I would try with owner: user._id directly rather that using $oid or BSON.ObjectId.

For the _id, could you simply leave it out and let the driver take care of it?

Hi thanks for reply. In my case the user._id is already a string as it was stringified earlier in code.

As far as _id goes, I’ve tried that too and I get a different error from Realm saying _id is required, which is weird because in the docs for Realm Web the insert examples don’t have _id either.

Could you share your schema? It might give us some ideas.

Have you tried with owner: { $oid : user._id }? But I doubt that $oid would work in this context. I have seen it with the Data API and with EJSON representation, not with real documents.

Sure, here is the Asset schema:

export class Asset extends Realm.Object<Asset> {
  _id!: BSON.ObjectId;
  owner!: User; // Relationship to User schema
  name!: string;
  s3Object!: S3Object; // Embedded Realm object
  /** file size */
  size!: number;
  tags!: Set<string>;
  synced!: boolean;
  variant?: AssetVariant; // Embedded Realm object
  thumbnail?: S3Thumbnail; // Embedded Realm object
  dateCreated!: Date;

  static schema: ObjectSchema = {
    properties: {
      _id: {
        type: "objectId",
        default: () => new BSON.ObjectId(),
      owner: "User",
      name: "string",
      s3Object: "S3Object",
      size: "int",
      tags: "string<>",
      synced: {
        type: "bool",
        default: () => false,
      variant: "AssetVariant?",
      thumbnail: "S3Thumbnail?",
      dateCreated: {
        type: "date",
        default: () => new Date(),
    primaryKey: "_id",

Yes i’ve tried that but gives me the same error as originally asked in question (Invalid function call).

Yea as you may have seen in the commented code from the original post, I tried just sending { owner: new BSON.ObjectId(user._id) } but that for some reason just sends an empty object to the request, in which i get an:
SchemaValidationFailedWrite Error as it sends an empty object and thus get type mismatch.

I do not see anything obvious and my lack of experience with Realm and schema stops me from being helpful.

Hopefully someone more experiences with the specifics of your issue with show up.