0

These are 2 different collections in a database.I am not able to figure out how to dynamically fetch the values from the collections using java .

I want to fetch the values through java program but without using the hardcoded values like "VerifyEmail.LicenseKey" & "wsf:status.arg0.age" as mentioned above in the java code.Is there a way to fetch the values without hardcoding in java.

Collection 1:

{
"_id" : ObjectId("583567ac6c85e71adc1f8bae"),
"wsf:status" : {
    "arg0" : {
        "name" : "James",
        "phonenum" : NumberLong(9848222338),
        "age" : 18
        "status" : "N" 
       }
   },
 }

Query 1: Here I am using the hardcoded values to fetch the desired result from the collection 1.

db.xmlcoll1.find({"wsf:status.arg0.age":18})

Collection 2:

{
"_id" : ObjectId("582446686c85e73a70696666"),

"VerifyEmail" : {
    "xmlns" : "http://ws.cdyne.com/",
    "email" : "[email protected]",
    "LicenseKey" : 123
} }

Query 2:

Here I am using the hardcoded value of the element "VerifyEmail" to fetch the values.

db.xmlcoll.find({"VerifyEmail.LicenseKey":123});

1 Answer 1

1

You can try to use Morphia if performance is not critical for you. And use such constructions for queries:

underpaid = datastore.createQuery(Employee.class)
                 .field("age").lessThanOrEq(18)
                 .asList();
Sign up to request clarification or add additional context in comments.

4 Comments

How would look your expected query?
BasicDBObject query = new BasicDBObject(); query.put("wsf:status.arg0.status", "N"); DBObject result = collection.findOne(query); this is the query.But I am not able to figure out how to fetch "wsf:status.arg0" from the collection without making it static.
so... you want quirey document, get it's structure and use it without declaring manually in code for following quireies, am I right?
Yeah is that possible ?

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.