New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support MongoDB "query" logging #11419
Comments
Looks like it's possible to send queries from the MongoDB driver with https://docs.rs/mongodb/latest/mongodb/event/command/trait.CommandEventHandler.html Internal Context: https://prisma-company.slack.com/archives/C0239SYUZV1/p1645130088849539 |
Talked with @janpio a bit about it and here's an idea that might be simpler that's more similar to what we currently do with logging SQL queries. Before each of the mongodb driver calls, we serialize into a JSON log. Something like: logger.query(JSON.stringify({
findOne: "Pets",
document: document
}))
// Actual driver call
driver.db("Pets").findOne(document) This isn't going to be a standard MongoDB log, but they don't really have a standard. I think we could use the same format we have for $runCommandRaw. As with SQL, this logger would be enabled by: const prisma = new PrismaClient({
log: ['query'],
}) Goal is to help people understand the underlying queries were run. Bonus points if you can copy and paste it somewhere without changing the format, so it's easier to test the query manually. I prefer what @dpetrick mentioned about having it be in the format of the mongodb shell over the $runCommandRaw described above, but $runCommandRaw format (or some other logical format) would be fine too. It does seem like we'll need some way to deal with newlines in the queries and newlines as separators. For that, I can share what I've used before: http://ndjson.org/, but I don't have an opinion on this. |
|
We will be using something that would be useful for the mongo shell. Other libraries (like Mongoose) use a similar approach. |
Support for query logging for MongoDB queries, we use the same format used by the Mongo Shell and Mongoose, so the query could be executed directly in the Mongo shell. A few important things need to be noted: In DEBUG builds, the queries would be indented for easy reading In RELEASE builds, the queries are plain, without indentation or car returns This works exactly like the existing SQL query logging but a few details are not included: Query execution time (maybe in a near future) Query parameters (we don't use it) When we retake logging this would be an area where things could be heavily simplified using spans for query logging. Another important improvement would be using a logging macro instead of the current functions. This closes prisma/prisma#11419
Support for query logging for MongoDB queries, we use the same format used by the Mongo Shell and Mongoose, so the query could be executed directly in the Mongo shell. A few important things need to be noted: In DEBUG builds, the queries would be indented for easy reading In RELEASE builds, the queries are plain, without indentation or car returns This works exactly like the existing SQL query logging but a few details are not included: Query execution time (maybe in a near future) Query parameters (we don't use it) When we retake logging this would be an area where things could be heavily simplified using spans for query logging. Another important improvement would be using a logging macro instead of the current functions. This closes prisma/prisma#11419
Problem
Right now we don't have a way to log the underlying querying run against a MongoDB database. This will be important because the Prisma way of querying is higher-level than the database query and often it's not clear how you'd map a Prisma query to the underlying query.
Suggested Solution
We already support with other databases via
We should investigate supporting this for MongoDB too. One possible suggestion would be to see how other ORMs like Mongoose do logging.
The text was updated successfully, but these errors were encountered: