https://www.prisma.io/ logo
Join Slack
Powered by
# mongodb
  • m

    Mike Rudge

    06/13/2022, 7:37 PM
    Hey everyone. Got a question around handling multiple languages with prisma and mongodb. Ideally we would use Collation on MongoDB so that we can efficiently query and store multilingual collections, however I'm not sure how we would be able to do that with Prisma. Anyone have any experience / recommendations?
    ✅ 1
    🤔 1
    n
    • 2
    • 1
  • p

    PinkiePie

    06/23/2022, 6:35 PM
    hi, does anybody knows why Prisma generates such a heavy requests?
    Copy code
    db.Game.aggregate([{
        $match: {
            $expr: {
                $and: [{
                    $in: ["$_id", [ObjectId("62b456c7548b0f401c499f49"), ObjectId("62b456e21955d39f37f9e45c"), ], ],
                }, {
                    $or: [{
                        $ne: [{
                            $ifNull: ["$_id", null, ],
                        }, null, ],
                    }, {
                        $eq: ["$_id", null, ],
                    }, ],
                }, ],
            },
        },
    }, {
        $project: {
            _id: 1,
            name: 1,
        },
    }, ])
    _id
    is a mandatory field, so it can't be
    null
    , but we have a huge branch for it:
    Copy code
    $or: [{
                        $ne: [{
                            $ifNull: ["$_id", null, ],
                        }, null, ],
                    }, {
                        $eq: ["$_id", null, ],
                    }, ],
    v
    n
    • 3
    • 3
  • p

    PinkiePie

    06/28/2022, 5:46 AM
    can i somehow use
    bulkWrite
    with
    $runCommandRaw
    ?
    👀 1
    m
    n
    d
    • 4
    • 14
  • p

    PinkiePie

    06/28/2022, 6:02 AM
    and BTW is there any docs about using
    $runCommandRaw
    ? input type
    Prisma.InputJsonObject
    tells me nothing about which commands are supported and what kind of arguments they have
  • o

    Octal pixel

    06/28/2022, 3:59 PM
    Will there be support for optional nested composite type ? I have use case where I want to have nested composite types, and make some optional an incremental update them on different screens. As of now Prisma requires all of the the nest documents to have some sort of value.
    d
    • 2
    • 6
  • m

    McKay Bonham

    06/29/2022, 5:17 AM
    I love the potential of Prisma, but I'm not trying to do anything very advanced with it yet and all I'm getting are errors, no matter how many times I Google the documentation and try to grok it. Could someone please tutor me through just a few basic things?
    ✅ 1
    n
    • 2
    • 7
  • d

    Dmitri Pisarev

    06/30/2022, 5:54 PM
    Dear community, I need some help again. I have this field in my Prisma schema
    userId String @map("user") @db.ObjectId
    Now I’m trying to process this in my custom Prisma
    generator
    plugin, and I need access to
    @map("user")
    part. But I don’t see it anywhere in the schema DMMF for this field:
    Copy code
    {
      name: 'userId',
      kind: 'scalar',
      isList: false,
      isRequired: true,
      isUnique: false,
      isId: false,
      isReadOnly: true,
      type: 'String',
      hasDefaultValue: false,
      isGenerated: false,
      isUpdatedAt: false
    }
    Is this a bug or a missing feature? I need this real bad (I’m building an automated $jsonSchema generator for Mongodb out of Prisma schema) Basically I expected to see smth like
    dbName: 'user'
    there.
    p
    • 2
    • 3
  • m

    McKay Bonham

    07/01/2022, 10:58 PM
    If I have a document with an array in it, is there a way to Query for WHERE that array INCLUDES a certain value?
    ✅ 1
    • 1
    • 1
  • m

    McKay Bonham

    07/03/2022, 2:12 PM
    My schema has the following line under one type of document:
    Copy code
    level          Int         @default(2)
    But the level attribute isn't getting populated at all when I make a new document of this type. Why is that?
    ✅ 1
    • 1
    • 3
  • d

    Dmitri Pisarev

    07/05/2022, 6:52 AM
    Hey! A dumb question about m-n relations with Mongo. The docs say that reference IDs must be present at both sides. But why is that necessary? E.g. imagine
    Post.categories
    relation. In inverse relation
    Category.posts
    would explode the
    Category
    entity, there would be hundreds of thousands of entries in it. Besides, it may eventually lead to inconsistent date if
    Post.categories
    wouldn’t match
    Category.posts
    for some reason. So is there a way to only store the relation information on a
    Post
    side and query things based only on it? An alternative would be to get rid of m-n relations entirely and query for such relations manually. Which would be a shame of course.
    ✅ 1
    n
    j
    • 3
    • 18
  • d

    Dmitri Pisarev

    07/06/2022, 11:00 AM
    prisma rainbow➡️mongodb Folks, allow me to plug a package which we’ve just released that allows you to generate a $jsonSchema in the format that Mongo understands out of the Prisma schema file. Hope you’ll find it useful: https://github.com/joindeed/prisma-mongo-json-schema-generator And yes, I hope that eventually this functionality becomes a part of Prisma core 😉
    👏 1
  • e

    ezeikel

    07/07/2022, 8:17 AM
    Hey all, how do I select fields from a composite type/embedded document when doing a find? Selecting it like a relation doesn't seem to work for me
    ✅ 1
    n
    • 2
    • 2
  • m

    McKay Bonham

    07/07/2022, 7:15 PM
    So I'm loading a document and several child documents from my database, modifying both generations of documents programmatically depending what the end user clicks in the front end, and now I'm trying to save all the changes back to the database with as few database calls as possible. I'm getting errors when I just do
    Copy code
    prisma.parentDocument.update({
      where: {
        id: req.params.id
      },
      data: {
        ...req.body
      },
      select: {
        childDocuments: true
      }
    });
    , is there a way I can do all of these updates in one query?
    ✅ 1
    n
    • 2
    • 2
  • m

    Maciej Błędkowski

    07/15/2022, 7:33 PM
    need help on #general
  • v

    Vicente Matus

    07/25/2022, 5:08 PM
    Guys im currently using Prisma with MongoDB but i have the following problem
    Error: P1001
    `Can't reach database server at `cluster0...`:`27019`` `Please make sure your database server is running at `cluster0...`:`27019`.` Whenever i try to use
    npx prisma db pull
    in an existing MongoDB data base This is my DATABASE_URL
    mongodb+srv://<username>:<password>@<cluster>/<database>?retryWrites=true&w=majority
    I'm currently connected to MongoDB Atlas, and the cluster is allowing connections from all ip's. How can i solve this?
    ✅ 1
    s
    • 2
    • 9
  • e

    ezeikel

    07/25/2022, 7:48 PM
    I've raised this a couple months ago and even created a reproduction repo to prove it but for some reason my reproduction seemed pretty performant so I abandoned it BUT am I the only one who seems to get some really slow queries when trying any slightly complicated things with relation queries? My latest example is:
    ✅ 1
    s
    p
    • 3
    • 7
  • d

    Dmitri Pisarev

    07/27/2022, 12:47 PM
    Howdy! I have this in my db:
    Copy code
    User {
      groups: [{
        groupId: 'group1-id',
        membershipType: 'Member'
      }, {
        groupId: 'group2-id',
        membershipType: 'Admin'
      }]
    }
    I want
    User.groups.groupId
    to be a relation. It’s currently not possible to set relationships on composite types. Is there any workaround around this? Any better way to attach some attribute to a relationship?
    👀 1
    a
    v
    • 3
    • 4
  • p

    PlayWolfYT

    08/04/2022, 10:20 AM
    Hey there, im having trouble with newer version of the Mongo-URI... If I try to use for example "mongodb+srv://user:pass@xyz.mongodb.net/project" Prisma fails to connect with the error "Error creating a database connection. (An error occurred during DNS resolution: request timed out)", but if I try older version of the urls (provided by cloud mongo ui), for example "mongodb://user:pass@shard-00-00.xyz.mongodb.net:27017,shard-00-01.xyz.mongodb.net:27017,shard-00-02.xyz.mongodb.net/project" everything works fine. So basically
    Copy code
    <mongodb+srv://user:pass@xyz.mongodb.net/project>
    does not work and
    Copy code
    <mongodb://user:pass@shard-00-00.xyz.mongodb.net:27017>,<http://shard-00-01.xyz.mongodb.net:27017,shard-00-02.xyz.mongodb.net/project|shard-00-01.xyz.mongodb.net:27017,shard-00-02.xyz.mongodb.net/project>
    does
    👀 1
    n
    • 2
    • 3
  • p

    PlayWolfYT

    08/04/2022, 10:22 AM
    Anyone know why this could be happening?
  • p

    PlayWolfYT

    08/08/2022, 11:24 AM
    Hey there! I have the following field on my user:
    Copy code
    model User {
        id    String @id @default(auto()) @map("_id") @db.ObjectId
        name  String
        phone String? @unique()
    }
    As you can see, the phone number is optional and unique. Yet when I register a user without a phone number, I cannot register a second user without a phone number, as I get the error "Unique constraint failed on the constraint: 'User_phone_key' ". Any way to say that
    null
    is not a phone number and that it should not get counted as a unique value?
    ✅ 1
    d
    • 2
    • 2
  • g

    Guro Khundadze

    08/09/2022, 12:05 PM
    Hello! I have a few questions. I'm thinking to try Prisma with MongoDB connector but instead of real MongoDB we have AWS DocumentDB, are there any known issues regarding that, should i do it? AWS DocumentDB does not support public endpoints so I'm connecting to it from my local machine using SSH Tunneling, + we have an SSL connection. but Prisma gives me an error that names in certificate and hostname do not match since the hostname is the name of the machine running SSH tunnel, I was able to surpass the error with mongo shell or other tools by adding tlsInsecure=true to the connection string, but seems like in case of Prisma it's not getting recognised, any suggestions? Thanks!
    ✅ 1
    n
    • 2
    • 2
  • r

    Ruben

    08/22/2022, 8:39 PM
    Hi guys. In mongodb, it is possible to generate 2d and 2dsphere indexes. Do you know a way or a "hack" to force the @@index to be from 2d or 2dsphere type?
    ✅ 1
    p
    • 2
    • 4
  • ö

    Ömer Genç

    09/01/2022, 12:23 PM
    Hi guys, i want to create 2 collection like this.
    Copy code
    const tags = [
      {
        id: '1111111',
        name: 'big',
      },
      {
        id: '2222222',
        name: 'white',
      },
      {
        id: '3333333',
        name: 'expensive',
      },
    ];
    
    const products = [
      {
        id: 'aaaaaaaa',
        name: 'dress',
        price: 100,
        tags: ['1111111', '2222222'],
      },
      {
        id: 'bbbbbbbb',
        name: 'dress 2',
        price: 101,
        tags: ['1111111', '3333333'],
      },
    ];
    I used many-to-many relation and result this.
    Copy code
    const tags = [
      {
        id: '1111111',
        name: 'big',
        products: ['aaaaaa', 'bbbbbbb'],
      },
      {
        id: '2222222',
        name: 'white',
        products: ['aaaaaa'],
      },
      {
        id: '3333333',
        name: 'expensive',
        products: ['bbbbbbb'],
      },
    ];
    
    const products = [
      {
        id: 'aaaaaaaa',
        name: 'dress',
        price: 100,
        tags: ['1111111', '2222222'],
      },
      {
        id: 'bbbbbbbb',
        name: 'dress 2',
        price: 101,
        tags: ['1111111', '3333333'],
      },
    ];
    this is my schema
    Copy code
    model Product {
      id   String @id @default(auto()) @map("_id") @db.ObjectId
      name String
    
      tagIDs String[] @db.ObjectId
      tags   Tag2[]   @relation(fields: [tagIDs], references: [id])
    }
    
    model Tag2 {
      id String @id @default(auto()) @map("_id") @db.ObjectId
    
      productIDs String[]  @db.ObjectId
      products   Product[] @relation(fields: [productIDs], references: [id])
    }
    Thank you...
    ✅ 1
    m
    n
    • 3
    • 7
  • m

    Mohammed Almajid

    09/08/2022, 12:36 AM
    Hey there , I been facing issue with implmenting prisma with already existing mongodb project data not perfect in
    production
    the main issue is
    Copy code
    P2023
    "Inconsistent column data: {message}"
    because I have some fields are unions , could be string or number how to solve this issue ? is there anyway to tell prisma that field type could be string or number? the solution that I have is to put field type as
    json
    but is there better solution ?
    ✅ 1
    h
    • 2
    • 2
  • a

    Andrew Obrigewitsch

    09/08/2022, 7:52 PM
    How would I do a query to get data from a sub collection that's an array of objects? like this:
    Copy code
    collection {
      subCollections: [{address: "string"}]
    }
    I want to search by address.
    👀 1
    a
    v
    • 3
    • 2
  • s

    Sim Kai Chien

    09/12/2022, 3:34 PM
    Hi guys, Is it possible to have multiple schemas for a collection via prisma? Like something done via mongoose below: var schemaOne = new Schema({ "stype": { type: String, default: "one" }, "myid": String, "f1": String }); var schemaTwo = new Schema({ "stype": { type: String, default: "two" }, "myid": String, "f2": String }); var One = mongoose.schema('one', schemaOne, 'coll'); var Two = mongoose.schema('two', schemaTwo, 'coll');
    ✅ 1
    a
    • 2
    • 1
  • j

    Jake W

    09/21/2022, 9:12 PM
    anyone know how to solve this problem?
  • j

    Jake W

    09/21/2022, 9:12 PM
    `Invalid
    Prisma.member.findFirst()
    invocation in`
    /Users/jake/Desktop/neo-rewrite/src/utils/functions/clanning.ts:15:30
    12 export const getMember = async (Guild: GuildType, Query: number | MemberType | string | APIInteractionGuildMember): Promise<MemberModel | null> => {
    13     if (typeof Query === 'string') {
    14         const userId = await getIdFromUsername(Query).catch(err => { return 0 })
    → 15            return await Prisma.member.findFirst(
    Inconsistent column data: Malformed ObjectID: provided hex string representation must be exactly 12 bytes, instead got: "957114139052998716", length 18.
  • r

    Raphael Etim

    09/22/2022, 7:14 AM
    Hi @Jake W 👋 From the error message you shared, the ObjectId you passed as an argument is bigger than 12 bytes. You will need to pass an ObjectId that matches the 12bytes exactly.
    j
    n
    • 3
    • 7
  • v

    Vladi Stevanovic

    09/23/2022, 10:41 AM
    👋 Hello everyone! To streamline support for our Community, all questions about the Prisma ORM (Client, Studio, Migrate) will now be answered in #orm-help channel, and this channel will be archived next week. is now archived. We hope that this will allow us to help you more quickly and share the knowledge among all our community members. 😊 If you have any pending questions / issues, feel free to resolve them in the current threads or move the conversation into #orm-help! 🌿 Happy coding!