Spring MongoDb: Create indexes about unknown fields using bean classes
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I'm running against an issue I don't know whether it's possible to do.
I need to store a document class with known fields, but also I need to store it with unknown fields:
@Document
public class Metadata
@Indexed
private String user;
private Object metadata;
All these unknown fields are stored inside metadata
field.
However, I know someone of them. I mean, inside metadata
field there will be whichever thing user wants, but there're some fields application knows.
I'd like to know how to create indexes about these unknown-knowed metadata
fields.
Example:
user: user, metadata: known: v, unknown: nv }
I'd like to create an index at metadata.known
field.
The problem is, since this field is not set a a java bean field, I'm not able to annotated it as @Indexed
.
Any ideas?
spring spring-data-mongodb
add a comment |
I'm running against an issue I don't know whether it's possible to do.
I need to store a document class with known fields, but also I need to store it with unknown fields:
@Document
public class Metadata
@Indexed
private String user;
private Object metadata;
All these unknown fields are stored inside metadata
field.
However, I know someone of them. I mean, inside metadata
field there will be whichever thing user wants, but there're some fields application knows.
I'd like to know how to create indexes about these unknown-knowed metadata
fields.
Example:
user: user, metadata: known: v, unknown: nv }
I'd like to create an index at metadata.known
field.
The problem is, since this field is not set a a java bean field, I'm not able to annotated it as @Indexed
.
Any ideas?
spring spring-data-mongodb
add a comment |
I'm running against an issue I don't know whether it's possible to do.
I need to store a document class with known fields, but also I need to store it with unknown fields:
@Document
public class Metadata
@Indexed
private String user;
private Object metadata;
All these unknown fields are stored inside metadata
field.
However, I know someone of them. I mean, inside metadata
field there will be whichever thing user wants, but there're some fields application knows.
I'd like to know how to create indexes about these unknown-knowed metadata
fields.
Example:
user: user, metadata: known: v, unknown: nv }
I'd like to create an index at metadata.known
field.
The problem is, since this field is not set a a java bean field, I'm not able to annotated it as @Indexed
.
Any ideas?
spring spring-data-mongodb
I'm running against an issue I don't know whether it's possible to do.
I need to store a document class with known fields, but also I need to store it with unknown fields:
@Document
public class Metadata
@Indexed
private String user;
private Object metadata;
All these unknown fields are stored inside metadata
field.
However, I know someone of them. I mean, inside metadata
field there will be whichever thing user wants, but there're some fields application knows.
I'd like to know how to create indexes about these unknown-knowed metadata
fields.
Example:
user: user, metadata: known: v, unknown: nv }
I'd like to create an index at metadata.known
field.
The problem is, since this field is not set a a java bean field, I'm not able to annotated it as @Indexed
.
Any ideas?
spring spring-data-mongodb
spring spring-data-mongodb
asked Nov 15 '18 at 14:44
JordiJordi
4,59493989
4,59493989
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
As a guess, why don't you split the metadata Object
in two?
One for known fields that you can index and other for the unknown that you cannot index. For example:
@Document
public class Metadata
@Indexed
private String user;
@Indexed
private Object knownMetadata;
private Object unknownMetadata;
As a result you will have something similar to:
user: user, knownMetadata: knownField1: v, knownField2: nv, unknownMetadata: unknownField1: v, unknownField2: nv }
Are AllknownMetadata
sub-fields indexed?
– Jordi
Nov 15 '18 at 14:56
Not sure about that, how many known fields you have in the metadata? I'm asking because you can always create a an @Indexed field for each known parameter and keep the unknown in the metadataObject
– juanlumn
Nov 15 '18 at 15:12
add a comment |
For known fields you can create an index with the compound index annotation. It does not actually force you to have a compound index.
Consider this bean:
@CompoundIndexes(
@CompoundIndex(name="my_index", def = "'metadata.known' : 1", background=true),
)
@Document
@Document
public class Metadata
@Indexed
private String user;
private Object metadata;
This would now create an index on the field: metadata.known
- you can do this on any of the known fields and define them in the annotation.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53321949%2fspring-mongodb-create-indexes-about-unknown-fields-using-bean-classes%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
As a guess, why don't you split the metadata Object
in two?
One for known fields that you can index and other for the unknown that you cannot index. For example:
@Document
public class Metadata
@Indexed
private String user;
@Indexed
private Object knownMetadata;
private Object unknownMetadata;
As a result you will have something similar to:
user: user, knownMetadata: knownField1: v, knownField2: nv, unknownMetadata: unknownField1: v, unknownField2: nv }
Are AllknownMetadata
sub-fields indexed?
– Jordi
Nov 15 '18 at 14:56
Not sure about that, how many known fields you have in the metadata? I'm asking because you can always create a an @Indexed field for each known parameter and keep the unknown in the metadataObject
– juanlumn
Nov 15 '18 at 15:12
add a comment |
As a guess, why don't you split the metadata Object
in two?
One for known fields that you can index and other for the unknown that you cannot index. For example:
@Document
public class Metadata
@Indexed
private String user;
@Indexed
private Object knownMetadata;
private Object unknownMetadata;
As a result you will have something similar to:
user: user, knownMetadata: knownField1: v, knownField2: nv, unknownMetadata: unknownField1: v, unknownField2: nv }
Are AllknownMetadata
sub-fields indexed?
– Jordi
Nov 15 '18 at 14:56
Not sure about that, how many known fields you have in the metadata? I'm asking because you can always create a an @Indexed field for each known parameter and keep the unknown in the metadataObject
– juanlumn
Nov 15 '18 at 15:12
add a comment |
As a guess, why don't you split the metadata Object
in two?
One for known fields that you can index and other for the unknown that you cannot index. For example:
@Document
public class Metadata
@Indexed
private String user;
@Indexed
private Object knownMetadata;
private Object unknownMetadata;
As a result you will have something similar to:
user: user, knownMetadata: knownField1: v, knownField2: nv, unknownMetadata: unknownField1: v, unknownField2: nv }
As a guess, why don't you split the metadata Object
in two?
One for known fields that you can index and other for the unknown that you cannot index. For example:
@Document
public class Metadata
@Indexed
private String user;
@Indexed
private Object knownMetadata;
private Object unknownMetadata;
As a result you will have something similar to:
user: user, knownMetadata: knownField1: v, knownField2: nv, unknownMetadata: unknownField1: v, unknownField2: nv }
answered Nov 15 '18 at 14:53
juanlumnjuanlumn
2,0291722
2,0291722
Are AllknownMetadata
sub-fields indexed?
– Jordi
Nov 15 '18 at 14:56
Not sure about that, how many known fields you have in the metadata? I'm asking because you can always create a an @Indexed field for each known parameter and keep the unknown in the metadataObject
– juanlumn
Nov 15 '18 at 15:12
add a comment |
Are AllknownMetadata
sub-fields indexed?
– Jordi
Nov 15 '18 at 14:56
Not sure about that, how many known fields you have in the metadata? I'm asking because you can always create a an @Indexed field for each known parameter and keep the unknown in the metadataObject
– juanlumn
Nov 15 '18 at 15:12
Are All
knownMetadata
sub-fields indexed?– Jordi
Nov 15 '18 at 14:56
Are All
knownMetadata
sub-fields indexed?– Jordi
Nov 15 '18 at 14:56
Not sure about that, how many known fields you have in the metadata? I'm asking because you can always create a an @Indexed field for each known parameter and keep the unknown in the metadataObject
– juanlumn
Nov 15 '18 at 15:12
Not sure about that, how many known fields you have in the metadata? I'm asking because you can always create a an @Indexed field for each known parameter and keep the unknown in the metadataObject
– juanlumn
Nov 15 '18 at 15:12
add a comment |
For known fields you can create an index with the compound index annotation. It does not actually force you to have a compound index.
Consider this bean:
@CompoundIndexes(
@CompoundIndex(name="my_index", def = "'metadata.known' : 1", background=true),
)
@Document
@Document
public class Metadata
@Indexed
private String user;
private Object metadata;
This would now create an index on the field: metadata.known
- you can do this on any of the known fields and define them in the annotation.
add a comment |
For known fields you can create an index with the compound index annotation. It does not actually force you to have a compound index.
Consider this bean:
@CompoundIndexes(
@CompoundIndex(name="my_index", def = "'metadata.known' : 1", background=true),
)
@Document
@Document
public class Metadata
@Indexed
private String user;
private Object metadata;
This would now create an index on the field: metadata.known
- you can do this on any of the known fields and define them in the annotation.
add a comment |
For known fields you can create an index with the compound index annotation. It does not actually force you to have a compound index.
Consider this bean:
@CompoundIndexes(
@CompoundIndex(name="my_index", def = "'metadata.known' : 1", background=true),
)
@Document
@Document
public class Metadata
@Indexed
private String user;
private Object metadata;
This would now create an index on the field: metadata.known
- you can do this on any of the known fields and define them in the annotation.
For known fields you can create an index with the compound index annotation. It does not actually force you to have a compound index.
Consider this bean:
@CompoundIndexes(
@CompoundIndex(name="my_index", def = "'metadata.known' : 1", background=true),
)
@Document
@Document
public class Metadata
@Indexed
private String user;
private Object metadata;
This would now create an index on the field: metadata.known
- you can do this on any of the known fields and define them in the annotation.
answered Nov 15 '18 at 15:12
pandaadbpandaadb
4,63111226
4,63111226
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53321949%2fspring-mongodb-create-indexes-about-unknown-fields-using-bean-classes%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown