Closed gursahibsahni closed 8 months ago
Any particular reason you're querying against CustomerDAO
and not Customer
?
Any particular reason you're querying against
CustomerDAO
and notCustomer
?
Doesn't matter -- CustomerDAO's collection name is customer
. They both point to the same thing. Updated the question with clarity and better formatting.
FWIW - I am using the following codec registry in my datastore config
final var pojoCodecRegistry = fromRegistries(MongoClientSettings.getDefaultCodecRegistry(), fromProviders(PojoCodecProvider.builder().automatic(true).build()));
If you could put together a reproducer I'd be happy to take a look and see. This case is pretty well tested and years old so there must be something else in play I'm not seeing here.
@evanchooly I have added you to the project I am working on. I think that should help you to see the problem. Please let me know if by anyway I can help you more to look into it. You would need mongo on your local to run it and once you build. You would need to add a customer
POST http://localhost:8080/customers
{ "isNewCustomer": true, "name": "Gursahib", "address": [ { "number": "string", "sector": "string", "city": "New Delhi", "country": "India", "pincode": "string", "isActive": true } ], "activePhone": "9811723480", "phone": [ "0909090909" ], "notes": "customer notes", "customerTag": { "name": "big customer", "meaning": "some meaning" }, "customerOrderTag": { "name": "order tag", "meaning": "some meaning" } }
Then GET http://localhost:8080/customers?pn=9811723480
You would be able to see no results and be able to debug.
Thank you so much
@evanchooly I used to reproducer repo and figured out the problem. I still don't know what was the root issue. But here is the thing -
If you see the screenshot of the above mongo compass - there is no type discriminator to tell mongo how to deserialize. I think I was using an old version of Mongo and after the change in the version, the change wasn't percolated in IntelliJ (I hate when it does that). Now, when I have changed the mongo version, I see the _t
field has a value and can retrieve the value.
We can close the issue.
If you're working with data from older versions, look at the legacy()
method on MapperOptions
to recreate the older default settings.
Describe the bug Using Filters.eq for String based fields doesn't work. Example:
// DOES NOT work
datastore.find(CustomerDAO.class).filter(Filters.eq("activePhone", activePhone)).iterator().tryNext();
// DOES work
datastore.find(CustomerDAO.class).filter(Filters.eq("_id", new ObjectId(id))).iterator().tryNext();
// mongo client DOES work
datastore.getDatabase().getCollection("customer").find(eq("activePhone", activePhone));
Expected behavior Morphia should return data based on the activePhone data
Please complete the following information: