Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jnosql-dev] [nosql-dev] mongodb $elemMatch jnosql query equivalent

Hi Otavio,

Sorry for the very long delay, I had a deadline and couldn't test snapshot as I stuck to b5.
The main reason I didn't pass to the b6 was packages changes (jakarta.nosql.mapping.* -> jakarta.nosql.*)
... and I see no "DiscriminatorValue" annotation. Is going to be moved from org.eclipse.jnosql.mapping.*,
or it is not yet ready to be standardized?

I hesitate to put "non-standard" annotations to the API...

Kind regards,

Dmitry

On 5/18/2023 11:19 AM, Otavio Santana wrote:

Hey Dmitry, how are you?

Could you test with the latest version, 1.0.0-SNAPSHOT?

I fixed it on this PR.

It was an injection issue; I've created a new problem; for me, it is an excellent opportunity to increase our integration test by database modules.
 


On Wed, May 17, 2023 at 6:28 PM Dmitry Repchevsky <redmitry@xxxxxxx> wrote:

Hi Otavio,

When I inject MongoDBTemplate, it is injected without initialization (with no-arguments constructor).

IMHO there is a lack of DefaultMongoDBTemplateProducer similar to the junit test.

Best,

Dmitry

P.S. Here is what works for me:

-------------------------------------------------------------------------------------------------------------

public class MongoDBTemplateProducer {
    
    @Inject
    private Instance<MongoDBDocumentManager> manager;

    @Inject
    private DocumentEntityConverter converter;

    @Inject
    private DocumentWorkflow workflow;

    @Inject
    private DocumentEventPersistManager persistManager;

    @Inject
    private EntitiesMetadata entities;

    @Inject
    private Converters converters;

    private MongoDBTemplate mongo_template;
    
    @PostConstruct
    public void init() {        
        mongo_template = new DefaultMongoDBTemplate(manager,
            converter, workflow, entities, converters, persistManager);
    }

    @Produces @Named("default")
    public MongoDBTemplate getMongoDBTemplate() {
        return mongo_template;
    }
}

On 5/17/2023 6:52 PM, Otavio Santana wrote:
Hey Dmitry, it should be hidden.
You should inject the `MongoDBTemplate`.

Please, take a look at this sample:




On Wed, May 17, 2023 at 4:58 PM Dmitry Repchevsky via nosql-dev <nosql-dev@xxxxxxxxxxx> wrote:

Hi again,

There is a problem with  DefaultMongoDBTemplate as

@Inject
MongoDBTemplate template;
injects uninitialized DefaultMongoDBTemplate.

The class is protected:
https://github.com/eclipse/jnosql-extensions/blob/1.0.0-b5/jnosql-mongodb-extension/src/main/java/org/eclipse/jnosql/mapping/mongodb/DefaultMongoDBTemplate.java

So the only way to use it - copy to my own project.

Cheers,

Dmitry

P.S. The unit test works, because it is in the same package.

On 5/13/2023 8:54 AM, Dmitry Repchevsky via nosql-dev wrote:

Great!

Thank you, I used DocumentTemplate and was thinking about Criteria extension API, but direct query is a quick and good fix.

IMHO, the search in the arrays is the basic functionality independently of any document model.

Thank you again,

Dmitry

On 5/13/2023 8:44 AM, Otavio Santana wrote:

Hey Dmitry, how are you?

You can use the Filter directly if you use the MongoDBTemplate, you can check the MongoDB readme.

@Inject
MongoDBTemplate template;
...

Bson filter = eq("name", "Poliana");
Stream<Person> stream = template.select(Person.class , filter);

On Fri, May 12, 2023 at 5:00 PM Otavio Santana <otaviopolianasantana@xxxxxxxxx> wrote:
Hey Dmitry, how are you?

I hope that you are doing well.

I've included the JNoSQL discussion because what we can do is create a MongoDB extension to work with it.
Please, let me know your thoughts.

On Thu, May 11, 2023 at 1:12 PM Dmitry Repchevsky via nosql-dev <nosql-dev@xxxxxxxxxxx> wrote:

Hello,

Is there any possibility to query elements in the array via jnosql query?

I have (an example) data like:

{ "measures": [
    { "id": "weight", "value": 80},
    { "id": "height", "value": 180}
  ]
}

The mongodb query for this would look like:
db.person.find({"measures": {"$elemMatch": {"id": "weight", "value": 180}}});

The only query I found to do in jnosql is something like:
select * from person where measures.id = "weight" and measures.value = 180

Which is wrong as it found the person object that match.
Any even hacky solution would be welcome.

Cheers,

Dmitry





_______________________________________________
nosql-dev mailing list
nosql-dev@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/nosql-dev


--

Thanks a lot,

Twitter | Linkedin | Youtube



--

Thanks a lot,

Twitter | Linkedin | Youtube


_______________________________________________
nosql-dev mailing list
nosql-dev@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/nosql-dev
_______________________________________________
nosql-dev mailing list
nosql-dev@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/nosql-dev


--

Thanks a lot,

Twitter | Linkedin | Youtube



--

Thanks a lot,

Twitter | Linkedin | Youtube


Back to the top