Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-3342

Allow _id to be any type when no schema is provided

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: TypeScript

      Use Case

      As a Typescript user I want to be able to declare a schema-less collection that permits the _id field to be any type, instead of the default ObjectId so that code is written with less effort when I'm not concerned about type safety.

      Dependencies

      • Our type definitions we publish

      Unknowns

      • Is this possible? Currently we default the _id type to ObjectId because when its not specified that is infact the type that mongodb will insert but it doesn't mean users can't use another type.
      • Is this a breaking change if introduced later? Seems like we're strict now and could reduce the strictness later without harm.

      Acceptance Criteria

      Implementation Requirements
      • I should be able to have this code be errorless:
        Unable to find source-code formatter for language: typescript. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
        const collection = db.collection('c') // No schema
        collection.insertOne({ _id: 1 }) // non ObjectId type
        
      Testing Requirements
      • Uncomment test found in test/types/community/collection/insertX.test-d.ts
      Documentation Requirements
      • n/a
      Follow Up Requirements
      • n/a

            Assignee:
            Unassigned Unassigned
            Reporter:
            neal.beeken@mongodb.com Neal Beeken
            Votes:
            4 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated: