You are not logged in.
Pages: 1
mongodb+windows+lazarus
TORMTest= class(TORM)
private
FIdempotency_Key: RawUtf8;
public
class procedure InitializeTable(const Server: IRestOrmServer; const FieldName: RawUtf8; Options: TOrmInitializeTableOptions); override;
published
property Idempotency_Key: RawUtf8 read FIdempotency_Key write FIdempotency_Key stored AS_UNIQUE;
end;
class procedure TORMTest.InitializeTable(const Server: IRestOrmServer; const FieldName: RawUtf8; Options: TOrmInitializeTableOptions);
var
B: boolean;
begin
inherited InitializeTable(Server, FieldName, Options);
// B := Server.CreateSqlIndex(TORMTest, ['User_ID', 'create_time', 'update_time', 'subject'], False);
// B := Server.CreateSqlIndex(TORMTest, 'Idempotency_Key', True);
B := Server.CreateSqlMultiIndex(TORMTest, ['Idempotency_Key'], True);
end;
Why isn't Idempotency_Key a unique index? Did I make a mistake somewhere?
Last edited by testgary (2025-09-10 15:16:06)
Offline
Why do you say it is not unique?
It should go into TMongoCollection.EnsureIndex() then create the index if needed.
What does this method returns?
What are the logs? (always ensure you enabled the logs and provide them as a link here to investigate)
Offline
class procedure TORMTest.InitializeTable(const Server: IRestOrmServer; const FieldName: RawUtf8; Options: TOrmInitializeTableOptions);
begin
// inherited InitializeTable(Server, FieldName, Options);
Server.CreateSqlIndex(TORMTest, ['User_ID', 'create_time', 'update_time', 'subject'], False);
Server.CreateSqlIndex(TORMTest, 'Idempotency_Key', True);
end;
I just checked and found that commenting out "inherited" would work. As for whether to include "stored AS_UNIQUE", it seems to make no difference. I haven't written the log yet.
Offline
Pages: 1