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 findRaw doesn't seem to work

See original GitHub issue

Bug description

I can’t seem to use the MongoDB findRaw command successfully. I can verify that findFirst works though on the same client. For example…

// doesnt work
console.log(await client.user.findRaw({
  filter: {
    id: {$eq: '6M4D3ncvpAWy2Fo8T'}
  }
}))

// does work
console.log(await client.user.findFirst({
  where: {
    id: '6M4D3ncvpAWy2Fo8T'
  }
}))

Note: I don’t think its related to how the IDs are defined. if i include another basic string field and try to query on that it still doesnt work. Nor a basic Int field.

How to reproduce

  1. Generate a client with the above schema. (Note that our IDs do not use ObjectIds but instead are just unique strings)
  2. Try the console.log statements above

Expected behavior

I expect at least one record to be found.

Prisma information

my schema is very basic:

generator client {
  provider = "prisma-client-js"
  output   = "./generated/mongo-db"
  previewFeatures = ["mongoDb"]
}

datasource db {
  provider = "mongodb"
  url      = env("MONGO_DATABASE_URL")
}

model User {
  id    String  @unique @id  @map("_id") 

  @@map("users")
}

Environment & setup

  • OS: PopOS
  • Database: MongoDB
  • Node.js version: 16.13.2

Prisma Version

prisma                  : 3.10.0
@prisma/client          : 3.10.0
Current platform        : debian-openssl-1.1.x
Query Engine (Node-API) : libquery-engine 73e60b76d394f8d37d8ebd1f8918c79029f0db86 (at node_modules/@prisma/engines/libquery_engine-debian-openssl-1.1.x.so.node)
Migration Engine        : migration-engine-cli 73e60b76d394f8d37d8ebd1f8918c79029f0db86 (at node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x)
Introspection Engine    : introspection-core 73e60b76d394f8d37d8ebd1f8918c79029f0db86 (at node_modules/@prisma/engines/introspection-engine-debian-openssl-1.1.x)
Format Binary           : prisma-fmt 73e60b76d394f8d37d8ebd1f8918c79029f0db86 (at node_modules/@prisma/engines/prisma-fmt-debian-openssl-1.1.x)
Default Engines Hash    : 73e60b76d394f8d37d8ebd1f8918c79029f0db86
Studio                  : 0.458.0

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
millspcommented, Mar 3, 2022

Hey @stringbeans, since ids are represented with ObjectIds or $oid on the db level, you need to build your query like the following:

    const users = await prisma.user.findRaw({
        filter: {
            _id: { $eq: { $oid: "6202ec178be26d2b28adc075" } },
        },
    })
2reactions
stringbeanscommented, Mar 4, 2022

@janpio yes thats correct! even if i try searching by other fields (ie. not the id field) i still cannot get results back…

@matthewmueller yes! we are working with the collections created by the MeteorJS framework. we’re relatively inexperienced with that framework, but from what i understand, MeteorJS does not use ObjectIDs for their id fields but instead uses an internal package meteor/random to generate the ids. its something to do with how they manage optimistic UI changes… this forum post touches on it: https://forums.meteor.com/t/using-mongos-random-ids-instead-of-meteors/17184/10

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mongoose near maxDistance doesn't seem to have an effect
I'm trying to write a simple query in Mongoose that returns a number of nearby results that all have GeoJSON properties. However, I'm...
Read more >
UnmarshalBSON having different behavior than ... - MongoDB
Hi there, I am trying to work with an interface{} I have an object ... for the interface, doesn't seem to be set,...
Read more >
find — MongoDB Manual
Changed in version 4.4: MongoDB deprecates the oplogReplay option to the find command. The optimization enabled by this flag in previous versions now...
Read more >
Building a BSON filter from raw query string - MongoDB
I'm using the mongocxx driver and want to use some tested queries from the mongo shell instead of building them inconveniently with the...
Read more >
WMS 2.0 corrupted MongoDB - Wyse Management Suite - Dell
I'm looking at the logs in MongoDB and it seems to be that the database ... calculated block checksum doesn't match expected checksum...
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