Skip to content
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

Map schema type converts UUID into plain string #13657

Closed
2 tasks done
men232 opened this issue Jul 26, 2023 · 1 comment · Fixed by #13704
Closed
2 tasks done

Map schema type converts UUID into plain string #13657

men232 opened this issue Jul 26, 2023 · 1 comment · Fixed by #13704
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@men232
Copy link

men232 commented Jul 26, 2023

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Mongoose version

7.4.1

Node.js version

18

MongoDB server version

4.4

Typescript version (if applicable)

No response

Description

Seems Map schema type makes unnecessary conversion via __schemaType.applyGetters for updates query. I noted it when developing my custom types that based on MongooseBuffer, i just tried Map + UUID combination and got the same issue.

Steps to Reproduce

import mongoose from 'mongoose';
import { randomUUID } from 'node:crypto';

const Schema = new mongoose.Schema(
  {
    doc_map: {
      type: mongoose.Schema.Types.Map,
      of: mongoose.Schema.Types.UUID,
    },
  },
  { collection: 'users_test' },
);

const User = mongoose.model('TestUser', Schema);

async function test() {
  const user = new User({
    doc_map: new Map([
      ['role_1', randomUUID()],
      ['role_2', randomUUID()],
    ]),
  });

  await user.save();

  // all good here
  console.log(user.doc_map);

  // trying to update
  user.doc_map.set('role_1', randomUUID());

  await user.save();

  // got string in doc_map -> role_1
}

test().catch(console.error);

Expected Behavior

No response

@IslandRhythms IslandRhythms added the confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. label Jul 26, 2023
@IslandRhythms
Copy link
Collaborator

I couldn't get it to print via a console log but it does show as such in the db

image

@vkarpov15 vkarpov15 added this to the 7.4.3 milestone Jul 28, 2023
vkarpov15 added a commit that referenced this issue Aug 8, 2023
fix: avoid applying map property getters when saving
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants