I have some data in MongoDB, the data structure is like
{"a":{"b":[1,2,3,4,5],"c":[a,b,c,d,e]}}
1--->a
2--->b
3--->c
4--->d
5--->e
I want get the right part value by the left like search b by 2
How can I do this Thank you very much
What I would suggest is to modify your structure to be able to make a query you want. My suggested structure is the following:
{
a: [
{b: 1, c: "a"},
{b: 2, c: "b"},
.
.
.
]
}
Then having your b value, you will be able to get the c one:
db.yourCollection.find({"a.b": "your_b_value"})
UPDATE by request of the question author
To make your query by range execute the following query:
db.yourCollection.find({"a.b": {$gte: 400.0}, "a.b": {$lte: 400.3}})
mongo shell?barray? Am I getting it correct: you have some valueXwhich has the indexiinsidebfield. You want to get theith element ofcarray?