0

I'm trying to add a unique composite key in my document as follows:

@Document
@CompoundIndexes({
    CompoundIndex(def = "{'firstName':1, 'lastName':1}", name = "compound_index_1", unique = true)
})

But I'm getting the error:

An annotation argument must be a compile-time constant.

can anybody help me?

1 Answer 1

5

Arrays are passed to annotations differently in Kotlin. Check out the docs on kotlinlang and you'll see this snippet down near the bottom:

// Kotlin 1.2+:
@AnnWithArrayMethod(names = ["abc", "foo", "bar"]) 
class C

// Older Kotlin versions:
@AnnWithArrayMethod(names = arrayOf("abc", "foo", "bar")) 
class D

So your curly braces aren't going to work here, you'll need square brackets.

@Document
@CompoundIndexes(value = [
    CompoundIndex(def = "{'firstName':1, 'lastName':1}",
                  name = "compound_index_1", unique = true)
    ])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.