In my collection, dates are stored in updated colu...
# mongodb
c
In my collection, dates are stored in updated column as:
Copy code
ISODate("2008-02-25T00:00:00Z"),
when I try to query with:
Copy code
$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
Copy code
$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
Copy code
updated    DateTime?
n
Hey Christopher 👋 I tried to reproduce this Considering this schema file:
Copy code
generator 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:
Copy code
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:
Copy code
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 Object
c
I didn't think it would matter, but maybe it does. I'm using a pipeline with aggregation
Copy code
const result = await prisma.name.aggregateRaw(
			{
				pipeline: [
					{
						$match: { 
							updated: { $gte: new Date("1970-01-01").toISOString() },
							nameParts: { $in: nameParts }
						}
					},
...
👋
I can add any other field in place of updated, still get results. Just fails when I try with a datetime
n
I tried it with aggregateRaw and findRaw and indeed I didn't get any records 🤔 Can you please create a GitHub Issue here, so that our team could have a look at this
c
Yep, thx