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

Mongoose service not returning Map attribute #2241

Closed
iammatis opened this issue Mar 3, 2021 · 1 comment
Closed

Mongoose service not returning Map attribute #2241

iammatis opened this issue Mar 3, 2021 · 1 comment

Comments

@iammatis
Copy link

iammatis commented Mar 3, 2021

Steps to reproduce

Having a mongoose model with attribute of type Map:

module.exports = app => {
  const modelName = 'users';
  const mongooseClient = app.get('mongooseClient');

  const schema = new mongooseClient.Schema({
    firstName: {type: String},
    lastName: {type: String},
    roles: {
      type: Map,
      of: Boolean
    },
    meta: {type: Object}
  }, {
    timestamps: true,
    strict: false
  });

  return mongooseClient.model(modelName, schema);
};

And Class:

const {Service} = require('feathers-mongoose');

exports.Users = class Users extends Service {}

(Hooks are untouched)

Expected behavior

Attribute roles should be returned as any other attribute.

Actual behavior

Attribute roles is being returned empty ("roles": {}), but logging context in after create hook shows roles being there (as a Map)

Module versions

{
  "@feathersjs/authentication": "^4.5.11",
  "@feathersjs/authentication-local": "^4.5.11",
  "@feathersjs/authentication-oauth": "^4.5.11",
  "@feathersjs/configuration": "^4.5.11",
  "@feathersjs/errors": "^4.5.11",
  "@feathersjs/express": "^4.5.11",
  "@feathersjs/feathers": "^4.5.11",
  "@feathersjs/socketio": "^4.5.11",
  "@feathersjs/transport-commons": "^4.5.11",
  "feathers-mongoose": "^8.3.1",
  "mongoose": "^5.11.17"
}

NodeJS version:
node:14.15.3

Issue duplicated from feathersjs-ecosystem/feathers-mongoose#398

@iammatis
Copy link
Author

This was a dumb mistake of mine, all I had to add was schema.set('toObject', {flattenMaps: true}); into my model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant