Christopher Schaub
05/12/2022, 10:55 AMISODate("2008-02-25T00:00:00Z"),
when I try to query with:
$match: {
updated: { $gte: new Date("1970-01-01").toISOString() },
nameParts: { $in: nameParts }
}
I get no results, unless I comment out updated then it works just fine. I've also tried
$match: {
updated: { $gte: new Date("1970-01-01") },
nameParts: { $in: nameParts }
}
No dice. It seems you can't use ISODate() here with typescript? In my schema, updated is
updated DateTime?
Nurul
05/12/2022, 11:11 AMgenerator client {
provider = "prisma-client-js"
binaryTargets = ["native"]
}
datasource db {
provider = "mongodb"
url = env("DATABASE_URL")
}
model users {
id String @id @default(auto()) @map("_id") @db.ObjectId
email String
name String
password String
time DateTime
}
And this Query:
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();
async function main() {
await prisma.users.create({
data: {
email: "<mailto:alice1@prisma.io|alice1@prisma.io>",
name: "Alice1",
password: "123456",
time: new Date("2008-02-25T00:00:00Z"),
},
});
const findQuery = await prisma.users.findMany({
where: {
time: {
gte: new Date("1970-01-01"),
},
},
});
console.log("findQuery", findQuery);
}
main()
.catch((e) => {
throw e;
})
.finally(async () => {
await prisma.$disconnect();
});
I can get the matching records
Output:
findQuery [
{
id: '627cea77a5677d827f7f882f',
email: '<mailto:alice1@prisma.io|alice1@prisma.io>',
name: 'Alice1',
password: '123456',
time: 2008-02-25T00:00:00.000Z
}
]
It's working perfectly with Date ObjectNurul
05/12/2022, 11:12 AMNurul
05/12/2022, 11:13 AMChristopher Schaub
05/12/2022, 11:16 AMconst result = await prisma.name.aggregateRaw(
{
pipeline: [
{
$match: {
updated: { $gte: new Date("1970-01-01").toISOString() },
nameParts: { $in: nameParts }
}
},
...
👋Christopher Schaub
05/12/2022, 11:16 AMNurul
05/12/2022, 12:10 PMChristopher Schaub
05/12/2022, 12:15 PM