P
Prisma4d ago
Seb

mongo dates without JS Date object?

is it possible to insert a document where a property is 'dateTime' without having it be a date object? I'm open to using rawCommand as well. The issue is i've build a logging service and each log has about 15-16 timestamp, which I'll want to query on for insight later on, but would involve having to convert each date on the incoming log, which are many, so ideally I'd find a way around that.
5 Replies
RaphaelEtim
RaphaelEtim3d ago
Hi @Seb You can use use $runCommandRaw method for this. This should allow you to insert datetime values without explicitly converting each timestamp in your code.
RaphaelEtim
RaphaelEtim3d ago
You should also be aware that using $runCommandRaw can result in date strings instead of ISODate objects, which might cause issues when querying later. You should be able to workaround it by using the $date operator as mentioned here https://github.com/prisma/prisma/issues/14815#issuecomment-1902571592
GitHub
Mongo $runCommandRaw() bulk update operation results in `new Date()...
Bug description The following command results in the field importDate being stored in the DB as a string, not an ISODate: import { PrismaClient } from '@prisma/client'; import uuid from ...
Seb
SebOP3d ago
hmmm -- this is more of a mongo thing that I'll have to google -- but you don't know by any chance what raw value mongo dataetime needs? the input is actually the unix number but I'll google that one on the mongo side of things
RaphaelEtim
RaphaelEtim3d ago
i think you should be able to use unix timestamp. you may also need the $numberLong operator. To insert a unix timestamp, i think this could work
await prisma.$runCommandRaw({
insert: 'your_collection_name',
documents: [
{
timestamp: {
$date: { $numberLong: "1234567890000" }
}
}
]
});
await prisma.$runCommandRaw({
insert: 'your_collection_name',
documents: [
{
timestamp: {
$date: { $numberLong: "1234567890000" }
}
}
]
});
Seb
SebOP3d ago
hmmmmm -- makes me think I'll let it be for now, perhaps compare the performance differences later, not quite sure how much compute power is going to be a bottleneck to ingestion vs bandwidth and I/O as there will be very few kb/log
Want results from more Discord servers?
Add your server