Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

207
Visualizações
Converting Timestamp to Cursor

I am using prisma schema with mongodb and what I am doing is having a date be generated like so:

model Book {
  id        String   @id @default(dbgenerated()) @map("_id") @db.ObjectId
  title     String
  author    Author   @relation(fields: [authorId], references: [id])
  authorId  String   @db.ObjectId
  createdAt DateTime @default(now())
}

node.createdAt is showing: 2021-11-29T12:38:22.248Z

So the tricky thing is a have two functions, one takes in a node from a list of edges and gets the createdAt property on the node the other converts the cursor back.

To convert the createdAt property I did this: Buffer.from((node.createdAt).getTime().toString()).toString('base64') which gives me: MTYzODE4OTUwMjI0OA==

Now to convert it back I have a function that takes in a cursor which I handled like this: return new Date(parseInt(Buffer.from(cursor, 'base64').toString())) this returns the same thing back: 2021-11-29T12:38:22.248Z

This is not working however and I think it's because the new Date returns a new instance. I'm having some real trouble getting this one to work

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda