Closed shreyasdn closed 5 years ago
Hi @shreyasdn can you provide a reproduceable test case so we can debug it and try to find a quickly solution.
hi,
In my schema i have added _id: { type: String, default: uuidV4 }. While the library creates the new schema the findById or find command does not work even if you give the correct value. I debugged the issue and found it to be because of newSchema = new connection.Schema({}, { collection: tenantCollectionName, });
. This automatically creates _id as ObjectID and hence it does not copy over the String one . Maybe we can pass options which would set the command to be like if(options._id){newSchema = new connection.Schema({options._id}, { collection: tenantCollectionName, })};
. Maybe i can raise a PR if i finish the fix and you can look it over?
hi, Have created a PR : https://github.com/jorgecuesta/mongoose-multitenancy/pull/13/. Do take a look and let me know.
No need for the PR or the issue as another way of creating schema covers this issue
hey @shreyasdn. What was they way of creating your schema that covers the issue? For future references, and maybe add it to docs.
hi, First off great library and thanks for writing this. When using your library if we have _id as String in this case there is no way to add this to the new schema and this does get copied over from the schema definition. Seems like the issue is due to creation of schema without parameters in index.js.