Discussion:
[mongodb-user] Mongodb retrieve data with API 3.x using Java
KARTHIK SHIVAKUMAR
2017-05-29 04:10:47 UTC
Permalink
Spec: Mongodb 3.x, Java 1.7,

I have a Created a Mongo Document inserted successfully to the Collection
~ "urldetls" which has *12 specific Unique keys with data in the values**.*

Question , I would like to retrieve the full document based on the value
searched within all of the documents.

Problem : I cannot retrieve the document based on the key of the document.

How can i retrieve ?

Would like to use the Mongodb API 3.x version using java .


Thx in Advance
Karthik
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.

For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+***@googlegroups.com.
To post to this group, send email to mongodb-***@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/5ea43e64-4541-424e-9673-f4b9b479fb27%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
KARTHIK SHIVAKUMAR
2017-05-30 12:08:16 UTC
Permalink
Spec: Mongodb 3.x, Java 1.7,

I have a Created a Mongo Document inserted successfully to the Collection
~ "urldetls" which has 8 specific <b> keys with Unique data in the
values.</b>

Question , I would like to retrieve the full document based on the
Unique value searched within all of the documents.

Problem : I cannot retrieve the document based on the key of the document.

Sample as

{

"_id" : ObjectId("5923c560131ffb1b84b5b6f4"),
"appBsId" : 100,
"infra" : "DEV",

"regNo1" : "101",
"env1" : "192.168.153.21",

"regNo2" : "102",
"env1" : "192.168.153.22",

"regNo3" : "103",
"env1" : "192.168.153.23",

}



How can i retrieve ? if searched "102" to retrieve the full document

Would like to use the Mongodb API 3.x version using java .
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.

For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+***@googlegroups.com.
To post to this group, send email to mongodb-***@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/e6495422-7606-4c8e-9745-f556f19eb5b7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
n***@gmail.com
2017-06-01 03:45:59 UTC
Permalink
HiSpec: Mongodb 3.x, Java 1.7,Criteria : All values in inserted document
are unique by default. Question : Need to fetch the document ( key/ values)
based on the search by value ? Hint : Precisely Need to fetch the document
based on 2 values. with regardsKarthik



--
View this message in context: http://mongodb.2344371.n4.nabble.com/Mongodb-retrieve-data-with-API-3-x-using-Java-tp15979p16058.html
Sent from the User mailing list archive at Nabble.com.
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.

For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+***@googlegroups.com.
To post to this group, send email to mongodb-***@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/1496288758951-16058.post%40n4.nabble.com.
For more options, visit https://groups.google.com/d/optout.
KARTHIK SHIVAKUMAR
2017-06-01 10:14:16 UTC
Permalink
Hi

Spec: Mongodb 3.x, Java 1.7,

{"_id" :
ObjectId("100..."),"appBsId":100,"infra":"DEV","regNo1":"101","env1":"192.168.153.21","regNo2":"102","env1":"192.168.153.22","regNo3":"103","env1":"192.168.153.23",}
{"_id" :
ObjectId("110..."),"appBsId":100,"infra":"DEV","regNo1":"101","env1":"192.168.153.24","regNo2":"102","env1":"192.168.153.25","regNo3":"103","env1":"192.168.153.26",}

I tried using Full text serach with Index capabilities as follows


db.BPEL_12C_DTLS.createIndex({regNo1:"text",regNo2:"text"})
db.BPEL_12C_DTLS.find({$text:{$search:"102"}})

Returned '0' result

How can i retrieve ? if searched "102" to retrieve the full document

Would like to use the Mongo-db API 3.x version using java .
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.

For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+***@googlegroups.com.
To post to this group, send email to mongodb-***@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/68fc3aad-4236-4898-9531-c582dc51b58b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
'Kevin Adistambha' via mongodb-user
2017-06-02 01:33:08 UTC
Permalink
Hi Karthik

I tried using Full text serach with Index capabilities as follows

I’m not sure I understand your question. Why are you using full text
indexes on an apparently numeric field?

if searched “102” to retrieve the full document

Could you give us an example scenario of what you are trying to query and
how the result should look like? Examples of what the query should and
should not return using the mongo shell would be best.

Best regards,
Kevin
​
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.

For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+***@googlegroups.com.
To post to this group, send email to mongodb-***@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/c6b64a2f-c27b-4a1f-8b72-a7bf176c5a7c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
KARTHIK SHIVAKUMAR
2017-06-05 04:56:09 UTC
Permalink
Hi Kevin

Spec: Mongodb 3.x, Java 1.7,


For the data in the Mongodb in a Collections as

{"_id" :
ObjectId("100..."),"appBsId":100,"infra":"DEV","regNo1":"101","env1":"192.168.153.21","regNo2":"101","env1":"192.168.153.22","regNo3":"102","env1":"192.168.153.23",}
{"_id" :
ObjectId("110..."),"appBsId":200,"infra":"DEV","regNo1":"201","env1":"192.168.153.24","regNo2":"202","env1":"192.168.153.25","regNo3":"203","env1":"192.168.153.26",}

The Data is unique inserted at all times.

Question If i need to fetch then whole document based on the value , ex :-
'102'
The query has to scan thru the collection and return the whole document ,
How ever the *search thru the collection cannot be done based on the key*
:- appBsId / infra / regNo1 / regNo2 / regNo3.

Please solution me for the same.
Post by KARTHIK SHIVAKUMAR
Spec: Mongodb 3.x, Java 1.7,
I have a Created a Mongo Document inserted successfully to the Collection
~ "urldetls" which has 8 specific <b> keys with Unique data in the
values.</b>
Question , I would like to retrieve the full document based on the
Unique value searched within all of the documents.
Problem : I cannot retrieve the document based on the key of the document.
Sample as
{
"_id" : ObjectId("5923c560131ffb1b84b5b6f4"),
"appBsId" : 100,
"infra" : "DEV",
"regNo1" : "101",
"env1" : "192.168.153.21",
"regNo2" : "102",
"env1" : "192.168.153.22",
"regNo3" : "103",
"env1" : "192.168.153.23",
}
How can i retrieve ? if searched "102" to retrieve the full document
Would like to use the Mongodb API 3.x version using java .
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.

For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+***@googlegroups.com.
To post to this group, send email to mongodb-***@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/b15a703c-a154-4979-9a37-fa8bdd3e00ff%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
KARTHIK SHIVAKUMAR
2017-06-06 04:13:36 UTC
Permalink
Hi Kevin

Spec: Mongodb 3.x, Java 1.7,


For the data in the Mongodb in a Collections as

{"_id" : ObjectId("100..."),"appBsId":
100,"infra":"DEV","regNo1":"101","env1":"192.168.153.21","regNo2":"101","env1":"192.168.153.22","regNo3":"102","env1":"192.168.153.23",}
{"_id" :
ObjectId("110..."),"appBsId":200,"infra":"DEV","regNo1":"201","env1":"192.168.153.24","regNo2":"202","env1":"192.168.153.25","regNo3":"203","env1":"192.168.153.26",}
{"_id" :
ObjectId("110..."),"appBsId":300,"infra":"DEV","regNo1":"301","env1":"192.168.153.27","regNo2":"302","env1":"192.168.153.28","regNo3":"303","env1":"192.168.153.29",}


Question If i need to fetch then whole document based on the value , ex :-
'102'

Collection should scann the value and return this

{"_id" : ObjectId("100..."),"appBsId":
100,"infra":"DEV","regNo1":"101","env1":"192.168.153.21","regNo2":"101","env1":"192.168.153.22","regNo3":
"102","env1":"192.168.153.23",}

How to achieve this query ?


with regards
Karthik
Post by KARTHIK SHIVAKUMAR
Hi Kevin
Spec: Mongodb 3.x, Java 1.7,
For the data in the Mongodb in a Collections as
ObjectId("100..."),"appBsId":100,"infra":"DEV","regNo1":"101","env1":"192.168.153.21","regNo2":"101","env1":"192.168.153.22","regNo3":"102","env1":"192.168.153.23",}
ObjectId("110..."),"appBsId":200,"infra":"DEV","regNo1":"201","env1":"192.168.153.24","regNo2":"202","env1":"192.168.153.25","regNo3":"203","env1":"192.168.153.26",}
The Data is unique inserted at all times.
Question If i need to fetch then whole document based on the value , ex :-
'102'
The query has to scan thru the collection and return the whole document ,
How ever the *search thru the collection cannot be done based on the key*
:- appBsId / infra / regNo1 / regNo2 / regNo3.
Please solution me for the same.
Post by KARTHIK SHIVAKUMAR
Spec: Mongodb 3.x, Java 1.7,
I have a Created a Mongo Document inserted successfully to the
Collection ~ "urldetls" which has 8 specific <b> keys with Unique data in
the values.</b>
Question , I would like to retrieve the full document based on the
Unique value searched within all of the documents.
Problem : I cannot retrieve the document based on the key of the document.
Sample as
{
"_id" : ObjectId("5923c560131ffb1b84b5b6f4"),
"appBsId" : 100,
"infra" : "DEV",
"regNo1" : "101",
"env1" : "192.168.153.21",
"regNo2" : "102",
"env1" : "192.168.153.22",
"regNo3" : "103",
"env1" : "192.168.153.23",
}
How can i retrieve ? if searched "102" to retrieve the full document
Would like to use the Mongodb API 3.x version using java .
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.

For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+***@googlegroups.com.
To post to this group, send email to mongodb-***@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/87ae4d4a-6956-4913-9792-59b945dca2ef%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
KARTHIK SHIVAKUMAR
2017-06-07 05:01:53 UTC
Permalink
Hi

Spec: Mongodb 3.x, Java 1.7,


For the data in the Mongodb in a Collections as ' IP_MON'

{"_id" : ObjectId("100..."),"appBsId":
100,"infra":"DEV","regNo1":"101","env1":"192.168.153.21","regNo2":"101","env1":"192.168.153.22","regNo3":"102","env1":"192.168.153.23"}
{"_id" :
ObjectId("110..."),"appBsId":200,"infra":"DEV","regNo1":"201","env1":"192.168.153.24","regNo2":"202","env1":"192.168.153.25","regNo3":"203","env1":"192.168.153.26"}
{"_id" :
ObjectId("110..."),"appBsId":300,"infra":"DEV","regNo1":"301","env1":"192.168.153.27","regNo2":"302","env1":"192.168.153.28","regNo3":"303","env1":"192.168.153.29"}


Needed : If i need to fetch then whole document based on the value , ex :-
'102'

In Mongodb UI : I am able to achieve the results by following commands


db.IPMON_TEST.createIndex({regNo1:"text"})
db.IPMON_TEST.find({ $text: { $search: "101" } })



Collection returns the value and return this

{"_id" : ObjectId("100..."),"appBsId":
100,"infra":"DEV","regNo1":"101","env1":"192.168.153.21","regNo2":"101","env1":"192.168.153.22","regNo3":
"102","env1":"192.168.153.23",}


Problem :- How can this be achieved in Java using
mongo-java-driver-3.4.0.jar ( 3.x API ) ????

Any Help is appreciated.

with regards
Karthik
Post by KARTHIK SHIVAKUMAR
Hi Kevin
Spec: Mongodb 3.x, Java 1.7,
For the data in the Mongodb in a Collections as
100,"infra":"DEV","regNo1":"101","env1":"192.168.153.21","regNo2":"101","env1":"192.168.153.22","regNo3":"102","env1":"192.168.153.23",}
ObjectId("110..."),"appBsId":200,"infra":"DEV","regNo1":"201","env1":"192.168.153.24","regNo2":"202","env1":"192.168.153.25","regNo3":"203","env1":"192.168.153.26",}
ObjectId("110..."),"appBsId":300,"infra":"DEV","regNo1":"301","env1":"192.168.153.27","regNo2":"302","env1":"192.168.153.28","regNo3":"303","env1":"192.168.153.29",}
Question If i need to fetch then whole document based on the value , ex :-
'102'
Collection should scann the value and return this
"102","env1":"192.168.153.23",}
How to achieve this query ?
with regards
Karthik
Post by KARTHIK SHIVAKUMAR
Hi Kevin
Spec: Mongodb 3.x, Java 1.7,
For the data in the Mongodb in a Collections as
ObjectId("100..."),"appBsId":100,"infra":"DEV","regNo1":"101","env1":"192.168.153.21","regNo2":"101","env1":"192.168.153.22","regNo3":"102","env1":"192.168.153.23",}
ObjectId("110..."),"appBsId":200,"infra":"DEV","regNo1":"201","env1":"192.168.153.24","regNo2":"202","env1":"192.168.153.25","regNo3":"203","env1":"192.168.153.26",}
The Data is unique inserted at all times.
Question If i need to fetch then whole document based on the value , ex
:- '102'
The query has to scan thru the collection and return the whole document
, How ever the *search thru the collection cannot be done based on the
key* :- appBsId / infra / regNo1 / regNo2 / regNo3.
Please solution me for the same.
Post by KARTHIK SHIVAKUMAR
Spec: Mongodb 3.x, Java 1.7,
I have a Created a Mongo Document inserted successfully to the
Collection ~ "urldetls" which has 8 specific <b> keys with Unique data in
the values.</b>
Question , I would like to retrieve the full document based on the
Unique value searched within all of the documents.
Problem : I cannot retrieve the document based on the key of the document.
Sample as
{
"_id" : ObjectId("5923c560131ffb1b84b5b6f4"),
"appBsId" : 100,
"infra" : "DEV",
"regNo1" : "101",
"env1" : "192.168.153.21",
"regNo2" : "102",
"env1" : "192.168.153.22",
"regNo3" : "103",
"env1" : "192.168.153.23",
}
How can i retrieve ? if searched "102" to retrieve the full document
Would like to use the Mongodb API 3.x version using java .
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.

For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+***@googlegroups.com.
To post to this group, send email to mongodb-***@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/1aafc833-47f6-48f0-a346-83dfbad1be11%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
'Kevin Adistambha' via mongodb-user
2017-06-21 07:23:40 UTC
Permalink
Hi Karthik

In general, you need to know your field name to retrieve your data. Without
knowing the field name, you cannot use indexes to retrieve your data, which
means that the query will do a collection scan.

Having said that, it is possible to use the new $objectToArray aggregation
stage in MongoDB 3.4 (currently not documented yet, see SERVER-18794
db.test.find()
{ "_id": ObjectId("5949d2905d2611258c0c41ab"), "a": "a0", "b": "b0", "c": "c0" }
{ "_id": ObjectId("5949d2905d2611258c0c41ac"), "a": "a1", "b": "b1", "c": "c1" }
{ "_id": ObjectId("5949d2905d2611258c0c41ad"), "a": "a2", "b": "b2", "c": "c2" }

String findValue = "c1";
System.out.println("Finding value "+findValue+"...");
MongoIterable<Document> agg = collection.aggregate(
Arrays.asList(
project(new Document("o", new Document("$objectToArray", "$$ROOT"))),
match(new Document("o.v", findValue)),
project(new Document("_id", 1))
)
);for (Document doc : agg) {
Document fullDoc = collection.find(doc).first();
System.out.println(fullDoc);
}

which will result in:

Finding value c1...
Document{{_id=5949d2905d2611258c0c41ac, a=a1, b=b1, c=c1}}

I tested this using MongoDB Java driver 3.4.1.

Best regards,
Kevin
​
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.

For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+***@googlegroups.com.
To post to this group, send email to mongodb-***@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/936ed326-d31d-4eb7-aa92-2be1f04dc727%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
KARTHIK N.S
2017-06-28 13:08:10 UTC
Permalink
Thx for suggestion
Post by 'Kevin Adistambha' via mongodb-user
Hi Karthik
In general, you need to know your field name to retrieve your data.
Without knowing the field name, you cannot use indexes to retrieve your
data, which means that the query will do a collection scan.
Having said that, it is possible to use the new $objectToArray
aggregation stage in MongoDB 3.4 (currently not documented yet, see
SERVER-18794 <https://jira.mongodb.org/browse/SERVER-18794>). As an
db.test.find()
{ "_id": ObjectId("5949d2905d2611258c0c41ab"), "a": "a0", "b": "b0", "c": "c0" }
{ "_id": ObjectId("5949d2905d2611258c0c41ac"), "a": "a1", "b": "b1", "c": "c1" }
{ "_id": ObjectId("5949d2905d2611258c0c41ad"), "a": "a2", "b": "b2", "c": "c2" }
String findValue = "c1";
System.out.println("Finding value "+findValue+"...");
MongoIterable<Document> agg = collection.aggregate(
Arrays.asList(
project(new Document("o", new Document("$objectToArray", "$$ROOT"))),
match(new Document("o.v", findValue)),
project(new Document("_id", 1))
)
);for (Document doc : agg) {
Document fullDoc = collection.find(doc).first();
System.out.println(fullDoc);
}
Finding value c1...
Document{{_id=5949d2905d2611258c0c41ac, a=a1, b=b1, c=c1}}
I tested this using MongoDB Java driver 3.4.1.
Best regards,
Kevin
​
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.

For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+***@googlegroups.com.
To post to this group, send email to mongodb-***@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/ad1250e4-2ead-4867-a094-7cbe8fef2fd5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Continue reading on narkive:
Loading...