Mongodb get specific field for java












0















I have a collections named as users and I want to get specific entry which is latitude and longitude. In mongodb shell, I achieved to get my desired result by typing that;



db.users.find({},{latitude:1,longitude:1})


But in java, I failed. What I have done in java is that;



List<Document> results = db.getCollection("users").find(eq("latitude":1,"longitude",1))


So, does anyone has an idea to solve this ?



here is my collection's structure;




{
"_id": "2",
"username": "",
"password": "
",
"firm": "SpringSource",
"roles": [
"client"
],
"items": [
{
"_id": "030b0b88-9b9b-4886-b78e-32ec8cd0abe9",
"item-id": "1111",
"item-name": "Tea latte",
"price": 11111,
"quantity": 11
},
{
"_id": "b320d345-630f-4068-8b50-63313b7d201b",
"item-id": "2222",
"item-name": "Mint Tea",
"price": 2222,
"quantity": 2222
},
{
"_id": "d51e5391-5741-4d33-a481-4139df4ffa0e",
"item-id": "3333",
"item-name": "Black Tea",
"price": 3333,
"quantity": 33
},
{
"_id": "961f52a3-d0d3-45e9-a1cb-475d2c9b272f",
"item-id": "4444",
"item-name": "Green Tea",
"price": 4444,
"quantity": 444
}
],
"latitude": "39.909062",
"longitude": "32.778401"
},
{
"_id": "3",
"username": "",
"password": "
",
"firm": "RedHat",
"roles": [
"client"
]
},
{
"_id": "1",
"username": "",
"password": "
",
"firm": "SpringSource",
"roles": [
"admin",
"client"
],
"items": [
{
"_id": "79c35305-54d1-477e-957d-782f4bf2145a",
"item-id": "11111",
"item-name": "Americano",
"price": 111,
"quantity": 11
},
{
"_id": "5c7e03eb-1fde-4932-a2bc-94a2f002b382",
"item-id": "2222",
"item-name": "Filter Coffee",
"price": 2222,
"quantity": 22
},
{
"_id": "a413c06c-4242-4b30-80a9-62e7d7b84fb3",
"item-id": "3333",
"item-name": "tea",
"price": 33333,
"quantity": 44444
}
],
"latitude": "39.877619",
"longitude": "32.682537"
}











share|improve this question

























  • Your java statement doesn't look like valid Java due to that semicolon. Is it a compile error, or what?

    – Compass
    Jan 3 at 14:45











  • Please explain exactly what happens when your code runs.

    – Steve11235
    Jan 3 at 14:49











  • @Steve11235 actually, Its a restful api call so I do not compile code but When I make restful GET call, it returns anything.

    – eccck
    Jan 3 at 14:55













  • @Compass semicolon is forgotten in comment but it exists in java code. Basically, my problem is finding equal statement of shell command in java. Shell command is "db.users.find({},{latitude:1,longitude:1}) " .

    – eccck
    Jan 3 at 15:44













  • stackoverflow.com/questions/6568910/… projections solved my problem.

    – eccck
    Jan 3 at 15:50
















0















I have a collections named as users and I want to get specific entry which is latitude and longitude. In mongodb shell, I achieved to get my desired result by typing that;



db.users.find({},{latitude:1,longitude:1})


But in java, I failed. What I have done in java is that;



List<Document> results = db.getCollection("users").find(eq("latitude":1,"longitude",1))


So, does anyone has an idea to solve this ?



here is my collection's structure;




{
"_id": "2",
"username": "",
"password": "
",
"firm": "SpringSource",
"roles": [
"client"
],
"items": [
{
"_id": "030b0b88-9b9b-4886-b78e-32ec8cd0abe9",
"item-id": "1111",
"item-name": "Tea latte",
"price": 11111,
"quantity": 11
},
{
"_id": "b320d345-630f-4068-8b50-63313b7d201b",
"item-id": "2222",
"item-name": "Mint Tea",
"price": 2222,
"quantity": 2222
},
{
"_id": "d51e5391-5741-4d33-a481-4139df4ffa0e",
"item-id": "3333",
"item-name": "Black Tea",
"price": 3333,
"quantity": 33
},
{
"_id": "961f52a3-d0d3-45e9-a1cb-475d2c9b272f",
"item-id": "4444",
"item-name": "Green Tea",
"price": 4444,
"quantity": 444
}
],
"latitude": "39.909062",
"longitude": "32.778401"
},
{
"_id": "3",
"username": "",
"password": "
",
"firm": "RedHat",
"roles": [
"client"
]
},
{
"_id": "1",
"username": "",
"password": "
",
"firm": "SpringSource",
"roles": [
"admin",
"client"
],
"items": [
{
"_id": "79c35305-54d1-477e-957d-782f4bf2145a",
"item-id": "11111",
"item-name": "Americano",
"price": 111,
"quantity": 11
},
{
"_id": "5c7e03eb-1fde-4932-a2bc-94a2f002b382",
"item-id": "2222",
"item-name": "Filter Coffee",
"price": 2222,
"quantity": 22
},
{
"_id": "a413c06c-4242-4b30-80a9-62e7d7b84fb3",
"item-id": "3333",
"item-name": "tea",
"price": 33333,
"quantity": 44444
}
],
"latitude": "39.877619",
"longitude": "32.682537"
}











share|improve this question

























  • Your java statement doesn't look like valid Java due to that semicolon. Is it a compile error, or what?

    – Compass
    Jan 3 at 14:45











  • Please explain exactly what happens when your code runs.

    – Steve11235
    Jan 3 at 14:49











  • @Steve11235 actually, Its a restful api call so I do not compile code but When I make restful GET call, it returns anything.

    – eccck
    Jan 3 at 14:55













  • @Compass semicolon is forgotten in comment but it exists in java code. Basically, my problem is finding equal statement of shell command in java. Shell command is "db.users.find({},{latitude:1,longitude:1}) " .

    – eccck
    Jan 3 at 15:44













  • stackoverflow.com/questions/6568910/… projections solved my problem.

    – eccck
    Jan 3 at 15:50














0












0








0








I have a collections named as users and I want to get specific entry which is latitude and longitude. In mongodb shell, I achieved to get my desired result by typing that;



db.users.find({},{latitude:1,longitude:1})


But in java, I failed. What I have done in java is that;



List<Document> results = db.getCollection("users").find(eq("latitude":1,"longitude",1))


So, does anyone has an idea to solve this ?



here is my collection's structure;




{
"_id": "2",
"username": "",
"password": "
",
"firm": "SpringSource",
"roles": [
"client"
],
"items": [
{
"_id": "030b0b88-9b9b-4886-b78e-32ec8cd0abe9",
"item-id": "1111",
"item-name": "Tea latte",
"price": 11111,
"quantity": 11
},
{
"_id": "b320d345-630f-4068-8b50-63313b7d201b",
"item-id": "2222",
"item-name": "Mint Tea",
"price": 2222,
"quantity": 2222
},
{
"_id": "d51e5391-5741-4d33-a481-4139df4ffa0e",
"item-id": "3333",
"item-name": "Black Tea",
"price": 3333,
"quantity": 33
},
{
"_id": "961f52a3-d0d3-45e9-a1cb-475d2c9b272f",
"item-id": "4444",
"item-name": "Green Tea",
"price": 4444,
"quantity": 444
}
],
"latitude": "39.909062",
"longitude": "32.778401"
},
{
"_id": "3",
"username": "",
"password": "
",
"firm": "RedHat",
"roles": [
"client"
]
},
{
"_id": "1",
"username": "",
"password": "
",
"firm": "SpringSource",
"roles": [
"admin",
"client"
],
"items": [
{
"_id": "79c35305-54d1-477e-957d-782f4bf2145a",
"item-id": "11111",
"item-name": "Americano",
"price": 111,
"quantity": 11
},
{
"_id": "5c7e03eb-1fde-4932-a2bc-94a2f002b382",
"item-id": "2222",
"item-name": "Filter Coffee",
"price": 2222,
"quantity": 22
},
{
"_id": "a413c06c-4242-4b30-80a9-62e7d7b84fb3",
"item-id": "3333",
"item-name": "tea",
"price": 33333,
"quantity": 44444
}
],
"latitude": "39.877619",
"longitude": "32.682537"
}











share|improve this question
















I have a collections named as users and I want to get specific entry which is latitude and longitude. In mongodb shell, I achieved to get my desired result by typing that;



db.users.find({},{latitude:1,longitude:1})


But in java, I failed. What I have done in java is that;



List<Document> results = db.getCollection("users").find(eq("latitude":1,"longitude",1))


So, does anyone has an idea to solve this ?



here is my collection's structure;




{
"_id": "2",
"username": "",
"password": "
",
"firm": "SpringSource",
"roles": [
"client"
],
"items": [
{
"_id": "030b0b88-9b9b-4886-b78e-32ec8cd0abe9",
"item-id": "1111",
"item-name": "Tea latte",
"price": 11111,
"quantity": 11
},
{
"_id": "b320d345-630f-4068-8b50-63313b7d201b",
"item-id": "2222",
"item-name": "Mint Tea",
"price": 2222,
"quantity": 2222
},
{
"_id": "d51e5391-5741-4d33-a481-4139df4ffa0e",
"item-id": "3333",
"item-name": "Black Tea",
"price": 3333,
"quantity": 33
},
{
"_id": "961f52a3-d0d3-45e9-a1cb-475d2c9b272f",
"item-id": "4444",
"item-name": "Green Tea",
"price": 4444,
"quantity": 444
}
],
"latitude": "39.909062",
"longitude": "32.778401"
},
{
"_id": "3",
"username": "",
"password": "
",
"firm": "RedHat",
"roles": [
"client"
]
},
{
"_id": "1",
"username": "",
"password": "
",
"firm": "SpringSource",
"roles": [
"admin",
"client"
],
"items": [
{
"_id": "79c35305-54d1-477e-957d-782f4bf2145a",
"item-id": "11111",
"item-name": "Americano",
"price": 111,
"quantity": 11
},
{
"_id": "5c7e03eb-1fde-4932-a2bc-94a2f002b382",
"item-id": "2222",
"item-name": "Filter Coffee",
"price": 2222,
"quantity": 22
},
{
"_id": "a413c06c-4242-4b30-80a9-62e7d7b84fb3",
"item-id": "3333",
"item-name": "tea",
"price": 33333,
"quantity": 44444
}
],
"latitude": "39.877619",
"longitude": "32.682537"
}








java mongodb mongo-java-driver






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 15:03







eccck

















asked Jan 3 at 14:44









eccckeccck

715




715













  • Your java statement doesn't look like valid Java due to that semicolon. Is it a compile error, or what?

    – Compass
    Jan 3 at 14:45











  • Please explain exactly what happens when your code runs.

    – Steve11235
    Jan 3 at 14:49











  • @Steve11235 actually, Its a restful api call so I do not compile code but When I make restful GET call, it returns anything.

    – eccck
    Jan 3 at 14:55













  • @Compass semicolon is forgotten in comment but it exists in java code. Basically, my problem is finding equal statement of shell command in java. Shell command is "db.users.find({},{latitude:1,longitude:1}) " .

    – eccck
    Jan 3 at 15:44













  • stackoverflow.com/questions/6568910/… projections solved my problem.

    – eccck
    Jan 3 at 15:50



















  • Your java statement doesn't look like valid Java due to that semicolon. Is it a compile error, or what?

    – Compass
    Jan 3 at 14:45











  • Please explain exactly what happens when your code runs.

    – Steve11235
    Jan 3 at 14:49











  • @Steve11235 actually, Its a restful api call so I do not compile code but When I make restful GET call, it returns anything.

    – eccck
    Jan 3 at 14:55













  • @Compass semicolon is forgotten in comment but it exists in java code. Basically, my problem is finding equal statement of shell command in java. Shell command is "db.users.find({},{latitude:1,longitude:1}) " .

    – eccck
    Jan 3 at 15:44













  • stackoverflow.com/questions/6568910/… projections solved my problem.

    – eccck
    Jan 3 at 15:50

















Your java statement doesn't look like valid Java due to that semicolon. Is it a compile error, or what?

– Compass
Jan 3 at 14:45





Your java statement doesn't look like valid Java due to that semicolon. Is it a compile error, or what?

– Compass
Jan 3 at 14:45













Please explain exactly what happens when your code runs.

– Steve11235
Jan 3 at 14:49





Please explain exactly what happens when your code runs.

– Steve11235
Jan 3 at 14:49













@Steve11235 actually, Its a restful api call so I do not compile code but When I make restful GET call, it returns anything.

– eccck
Jan 3 at 14:55







@Steve11235 actually, Its a restful api call so I do not compile code but When I make restful GET call, it returns anything.

– eccck
Jan 3 at 14:55















@Compass semicolon is forgotten in comment but it exists in java code. Basically, my problem is finding equal statement of shell command in java. Shell command is "db.users.find({},{latitude:1,longitude:1}) " .

– eccck
Jan 3 at 15:44







@Compass semicolon is forgotten in comment but it exists in java code. Basically, my problem is finding equal statement of shell command in java. Shell command is "db.users.find({},{latitude:1,longitude:1}) " .

– eccck
Jan 3 at 15:44















stackoverflow.com/questions/6568910/… projections solved my problem.

– eccck
Jan 3 at 15:50





stackoverflow.com/questions/6568910/… projections solved my problem.

– eccck
Jan 3 at 15:50












0






active

oldest

votes












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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54024547%2fmongodb-get-specific-field-for-java%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54024547%2fmongodb-get-specific-field-for-java%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas