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

strictQuery throw an error where it shouldn't #7178

Closed
abarriel opened this issue Oct 24, 2018 · 1 comment
Closed

strictQuery throw an error where it shouldn't #7178

abarriel opened this issue Oct 24, 2018 · 1 comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@abarriel
Copy link
Contributor

Hey!
I am wondering why the script below throw a validation error.
I set strictQuery to throw, but the filter in find is correct.

Solution found if a use a dot notation in the find filter, it works great.
There is a slice difference between dot notation and using an object notation in the filter (either it look for exactly the same object, or only the key provided) but still we should be able to perform a find with the two syntax.

	// solution found
	await Test.find({"customer.persona": "whatever"});
const mongoose = require("mongoose");
const Schema = mongoose.Schema;

const TestSchema = new Schema(
  {
    customer: {
      persona: String,
    },
  },
  { strictQuery: "throw", timestamps: true },
);

const Test = mongoose.model("Test", TestSchema);

mongoose.connect("mongodb://localhost:27017/test");

async function main() {
  const res = await Test.find({
    customer: {
      persona: "whatever",
    },
  });
  console.log(res);
}

main()
  .then(() => process.exit(0))
  .catch((err) => {
    console.log(err);
    process.exit(1);
  });
@vkarpov15 vkarpov15 added this to the 5.3.9 milestone Oct 29, 2018
@vkarpov15 vkarpov15 added the confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. label Oct 29, 2018
@vkarpov15
Copy link
Collaborator

Thanks for reporting, will fix ASAP

vkarpov15 added a commit that referenced this issue Oct 31, 2018
vkarpov15 added a commit that referenced this issue Oct 31, 2018
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

No branches or pull requests

2 participants