0 votes

doctrine/mongo-db-odm logs the following deprecation notices:

1) Since doctrine/mongodb-odm 2.1: The "boolean" mapping type is deprecated. Use "bool" instead.

2) Since doctrine/mongodb-odm 2.2: The "@Indexes" annotation used in class "App\Document\X" is deprecated. Specify all "@Index" and "@UniqueIndex" annotations on the class

Can you please have a look and adjust the document generation? Thanks!

in Solved by (190 points)
recategorized by

4 Answers

0 votes

Hi, thanks for the info, we will check it.

by Skipper developer (141k points)
0 votes

Hello,

Sorry for the late reply. We just started working on your issue.

Regarding 1), based on the documentation "boolean" is still referred to as datatype and there is no mention about "bool" in 2.2. documentation

https://www.doctrine-project.org/projects/doctrine-mongodb-odm/en/2.2/reference/basic-mapping.html#doctrine-mapping-types

Do you have any exact link where is stated that boolean is deprecated?

Regarding 2) this is only partially covered by documentation:

https://www.doctrine-project.org/projects/doctrine-mongodb-odm/en/2.2/reference/indexes.html#unique-index

There is still mentioned (in 2.2) that per-class @Indexes can be used.

Also, please provide exact link where is stated that this tag is deprecated.

by Skipper developer (141k points)

Hi,

The deprecation notices I provided were generated by mongodb-odm, so this is definetly in the code. However, it seems like the documentation wasn't updated properly (yet). It is mentioned in the UPGRADEs though.

boolean, integer and and int_id have been deprecated since 2.1: https://github.com/doctrine/mongodb-odm/blob/2.2.x/UPGRADE-2.1.md
They were removed in 3.0: https://github.com/doctrine/mongodb-odm/blob/2.2.x/UPGRADE-3.0.md

@Indexes was deprecated in 2.2 and support will be removed in 3.0: https://github.com/doctrine/mongodb-odm/blob/2.2.x/UPGRADE-2.2.md
It's just about the encapsulation and to avoid the deprecation notice, I just had to change this:

/**
* @ODM\Document(collection="catalog")
* @ODM\Indexes({
* @ODM\Index(name="productid", background=false, keys={"productId":"asc"}),
* @ODM\UniqueIndex(name="color
variant_id", background=false, sparse=true, keys={"colorVariantId":"asc"})
* })
*/

to this:

/**
* @ODM\Document(collection="catalog")
* @ODM\Index(name="productid", background=false, keys={"productId":"asc"})
* @ODM\UniqueIndex(name="color
variant_id", background=false, sparse=true, keys={"colorVariantId":"asc"})
*/

Thanks for the links. It's a pity that documentation is such outdated. This doesn't make confidence in the project.

We will implement these changes.

Because there is no documentation for this migration, what is the correct way how to define a multi-field index?

/**
* @Document(requireIndexes=true)
* @UniqueIndex(keys={"accountId3"="asc", "username3"="asc"}, name="test3", unique=true, order="asc", dropDups="true", background="true", safe="true", sparse="true")
* })
*/

I believe this can't be removed at all.....

Hi,

basically you just need to skip the encapsulation and add the annotations directly. In other words, just add @ODM\Index and @ODM\UniqueIndex annotations directly without surrounding them by @ODM\Indexes. No need to change anything else in your logic, because it is already correct. I just verified that this works for multi-field indexes, too:

  • Add a new index called "multifield" to one of my documents in Skipper18 and exported it to my symfony project.

  • That resulted in the following code:

/**
* @ODM\EmbeddedDocument
* @ODM\Indexes({
* @ODM\Index(name="QuantityIndex", keys={"quantity":"asc"}),
* @ODM\UniqueIndex(name="ean", background=false, keys={"ean":"asc"}),
* @ODM\Index(name="size", background=true, keys={"size":"asc"}),
* @ODM\Index(name="variantid", background=false, keys={"variantId":"asc"}),
* @ODM\UniqueIndex(name="size
variant_id", background=false, sparse=true, keys={"sizeVariantId":"asc"}),
* @ODM\UniqueIndex(name="multifield", keys={"ean":"asc","size":"asc"})
* })
*/
class Variant
{
...

  • I manually removed the encapsulation (i.e. remove the two lines "* @ODM\Indexes({" and "* })" and removed all the commas at the end of the other lines), so it looks like this:

/**
* @ODM\EmbeddedDocument
* @ODM\Index(name="QuantityIndex", keys={"quantity":"asc"})
* @ODM\UniqueIndex(name="ean", background=false, keys={"ean":"asc"})
* @ODM\Index(name="size", background=true, keys={"size":"asc"})
* @ODM\Index(name="variantid", background=false, keys={"variantId":"asc"})
* @ODM\UniqueIndex(name="size
variant_id", background=false, sparse=true, keys={"sizeVariantId":"asc"})
* @ODM\UniqueIndex(name="multifield", keys={"ean":"asc","size":"asc"})
*/
class Variant
{
...

  • Run bin/console doctrine:mongodb:schema:update in console

Result: A multi-field index was correctly added to mongodb.

Thanks for the reply. In this case, it's super easy ;-). I thought all indexes had to be defined directly on the field.

I will let you know with the update

The new beta is ready with discussed changes. Please try it and let me know.

https://www.skipper18.com/support/402/downloads-skipper-beta

Thanks for implementing this, but unfortunately there is a bug.

The export only works properly when creating a new document. If the file is already present, it only exports one ODM\Index and one ODM\UniqueIndex.

If I for example delete one of my Documents and let Skipper18 export it:

/**
* @ODM\EmbeddedDocument
* @ODM\Index(name="QuantityIndex", keys={"quantity":"asc"})
* @ODM\UniqueIndex(name="ean", background=false, keys={"ean":"asc"})
* @ODM\Index(name="size", background=true, keys={"size":"asc"})
* @ODM\Index(name="variantid", background=false, keys={"variantId":"asc"})
* @ODM\UniqueIndex(name="size
variant_id", background=false, sparse=true, keys={"sizeVariantId":"asc"})
*/

If the file already exists (= just exporting a second time), Skipper removes all indexes except the first of each type:

/**
* @ODM\EmbeddedDocument
* @ODM\Index(name="QuantityIndex", keys={"quantity":"asc"})
* @ODM\UniqueIndex(name="ean", background=false, keys={"ean":"asc"})
*
*
*
*/

Thanks for the info, we will check it.

0 votes

Hi,

the new beta is available. We migrated all booleans to bool, but the second point is not implemented. I'm waiting for your reply regarding multi-field indexes.

https://www.skipper18.com/support/402/downloads-skipper-beta

by Skipper developer (141k points)
0 votes

New version with implemented chages for 2)

https://www.skipper18.com/support/402/downloads-skipper-beta

by Skipper developer (141k points)