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

type for $push is incorrect. #12126

Closed
2 tasks done
imranbarbhuiya opened this issue Jul 19, 2022 · 2 comments
Closed
2 tasks done

type for $push is incorrect. #12126

imranbarbhuiya opened this issue Jul 19, 2022 · 2 comments
Labels
typescript Types or Types-test related issue / Pull Request

Comments

@imranbarbhuiya
Copy link

imranbarbhuiya commented Jul 19, 2022

Prerequisites

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

Mongoose version

^6.4.5

Node.js version

v18

MongoDB server version

5.0

Description

Type for $push is incorrect.

Steps to Reproduce

  1. Create a model
const categorySchema = new Schema({
	name: String
});

const mainSchema = new Schema({
	name: String,
	categories: [categorySchema]
});

const mainModel = new model(mainSchema, 'mainSchema');
  1. Try to $push to the categories field.
await mainModel.updateOne(
	{ name: 'name' },
	{
		$push: {
			categories: {
				name: 'ok'
			}
		}
	}
);

Expected Behavior

No response

@imranbarbhuiya
Copy link
Author

imranbarbhuiya commented Jul 19, 2022

Also 3rd issue for #12030 is only fixed when anyone uses new Schema but it's not fixed when passing like this

const userSchema = new Schema({
	users: [
		{
			username: { type: String },
			credit: { type: Number, default: 0 }
		}
	]
});

const userModel = model('user', userSchema);

const data = await userModel.findOne();
data!.users.push({ username: 'parbez' });
// ts warns to add credit which can be solved using Types.DocumentArray

cc: @mohammad0-0ahmad since you had fixed it

@IslandRhythms IslandRhythms added the typescript Types or Types-test related issue / Pull Request label Jul 22, 2022
@vkarpov15 vkarpov15 added this to the 6.4.7 milestone Jul 23, 2022
@vkarpov15 vkarpov15 modified the milestones: 6.4.7, 6.4.9 Jul 25, 2022
@vkarpov15
Copy link
Collaborator

Fixed in 6.5.1 with b57efec

@vkarpov15 vkarpov15 removed this from the 6.5.2 milestone Aug 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
typescript Types or Types-test related issue / Pull Request
Projects
None yet
Development

No branches or pull requests

3 participants