question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MongoDB: Collection with field with array content is not introspected with native type `@db.Array`

See original GitHub issue

Take this collection:

[{
  "_id": {
    "$oid": "61e20bbc7fef3b66f439373a"
  },
  "name": "Sports",
  "post_ids": [
    {
      "$oid": "61e20bbc7fef3b66f4393737"
    }
  ]
},{
  "_id": {
    "$oid": "61e20bbd7fef3b66f439373b"
  },
  "name": "Fashion",
  "post_ids": [
    {
      "$oid": "61e20bbc7fef3b66f4393737"
    }
  ]
},{
  "_id": {
    "$oid": "61e20bbd7fef3b66f439373c"
  },
  "name": "Programming",
  "post_ids": [
    {
      "$oid": "61e20bbc7fef3b66f4393737"
    },
    {
      "$oid": "61e20bbc7fef3b66f4393739"
    }
  ]
}]

Introspection result is:

model Category {
  id       String   @id @default(dbgenerated()) @map("_id") @db.ObjectId
  name     String   @unique
  post_ids String[] @db.ObjectId
}

But should be:

model Category {
  id       String   @id @default(dbgenerated()) @map("_id") @db.ObjectId
  name     String   @unique
  post_ids String[] @db.Array(ObjectId)
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

0reactions
matthewmuellercommented, Jan 17, 2022

Closing this issue since introspection is working as expected. I’ll link to another issue if there’s more work to be done.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Query an Array — MongoDB Manual
This page provides examples of query operations on array fields using the db.collection.find() method in mongosh . The examples on this page use...
Read more >
How Prisma Introspects a Schema from a MongoDB Database
To fill in the fields with their type, we get a sample of up to 1000 random records from each collection and loop...
Read more >
Avoid Unbounded Arrays — MongoDB Atlas
Storing arrays as field values allows you to model one-to-many or ... instead of across separate collections as you might in a relational...
Read more >
$all — MongoDB Manual
When passed an array of a nested array (e.g. [ [ "A" ] ] ), $all matches documents where the field contains the...
Read more >
How to query an array of objects to match any of the provided ...
You didnt get it. Indeed. I do not get it. The statement. foco_radiante: db.collection.findOne ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found