Comments (3)
The DescendRange signature is
DescendRange(index, lessOrEqual, greaterThan string, iterator func(key, value string) bool) error
So the line in your code:
tx.DescendRange("last_name", `{"name":{"last":""}}`, `{"name":{"last":"Ma"}}`, func(key, value string) bool {
should be
tx.DescendRange("last_name", `{"name":{"last":"Ma"}}`, `{"name":{"last":""}}`, func(key, value string) bool {
The buntdb.Desc
function inverses the Ascend*
and Descend*
params and results.
For example:
db, _ := buntdb.Open(":memory:")
db.Update(func(tx *buntdb.Tx) error {
tx.CreateIndex("last_name", "*", buntdb.Desc(buntdb.IndexJSON("name.last")))
tx.Set("1", `{"name":{"first":"Tom","last":"Johnson"},"age":"38"}`, nil)
tx.Set("2", `{"name":{"first":"Janet","last":"Prichard"},"age":"47"}`, nil)
tx.Set("3", `{"name":{"first":"Carol","last":"Anderson"},"age":"52"}`, nil)
tx.Set("4", `{"name":{"first":"Alan","last":"Cooper"},"age":"28"}`, nil)
tx.Set("5", `{"name":{"first":"Jack","last":"Ma"},"age":"20"}`, nil)
tx.Set("6", `{"name":{"first":"Blues","last":"Li"},"age":"31"}`, nil)
tx.Set("7", `{"name":{"first":"Pony","last":"Ma"},"age":"3"}`, nil)
tx.Set("8", `{"name":{"first":"Robin","last":"Li"},"age":"2"}`, nil)
tx.Set("9", `{"name":{"first":"Larry","last":"Liu"},"age":""}`, nil)
return nil
})
db.View(func(tx *buntdb.Tx) error {
fmt.Println("---------------------")
tx.Ascend("last_name", func(key, value string) bool {
fmt.Printf("%s: %s\n", key, value)
return true
})
fmt.Println("---------------------")
tx.AscendRange("last_name", `{"name":{"last":"Ma"}}`, `{"name":{"last":""}}`, func(key, value string) bool {
fmt.Printf("%s: %s\n", key, value)
return true
})
return nil
})
returns
2: {"name":{"first":"Janet","last":"Prichard"},"age":"47"}
5: {"name":{"first":"Jack","last":"Ma"},"age":"20"}
7: {"name":{"first":"Pony","last":"Ma"},"age":"3"}
9: {"name":{"first":"Larry","last":"Liu"},"age":""}
6: {"name":{"first":"Blues","last":"Li"},"age":"31"}
8: {"name":{"first":"Robin","last":"Li"},"age":"2"}
1: {"name":{"first":"Tom","last":"Johnson"},"age":"38"}
4: {"name":{"first":"Alan","last":"Cooper"},"age":"28"}
3: {"name":{"first":"Carol","last":"Anderson"},"age":"52"}
---------------------
5: {"name":{"first":"Jack","last":"Ma"},"age":"20"}
7: {"name":{"first":"Pony","last":"Ma"},"age":"3"}
9: {"name":{"first":"Larry","last":"Liu"},"age":""}
6: {"name":{"first":"Blues","last":"Li"},"age":"31"}
8: {"name":{"first":"Robin","last":"Li"},"age":"2"}
1: {"name":{"first":"Tom","last":"Johnson"},"age":"38"}
4: {"name":{"first":"Alan","last":"Cooper"},"age":"28"}
3: {"name":{"first":"Carol","last":"Anderson"},"age":"52"}
from buntdb.
It turned out that because of carelessness, I read the wrong order of passing parameters.
this small problem still needs your help answer, i am very sorry.
Finally,thank you for your help.
from buntdb.
No worries. Iām happy to help. :)
from buntdb.
Related Issues (20)
- Python bindings
- Enhancement: add new method GetWithTTL to return value together with TTL
- What happens if two funcs write to the db at the exact same time? HOT 1
- Get size of db on disk
- Does the data.db file support rewrite like redis AOF? HOT 2
- Dependencies update due?
- Feature Request: Delete inside iterator
- Question: cost/benefit of supporting generic types; and persisting secondary indexes
- Is it necessary to (defer) db.Close()?
- Expiry works only during runtime and is lost on shrink HOT 6
- index, or getting with different keys doesn't work HOT 1
- tx.Ascend doesn't work correctly HOT 1
- Does buntdb needs Go 1.18+ due to btree dependency? HOT 1
- Question: What is the format of .db file? HOT 1
- I wonder if we can find closest lat long for a given latlon from spatial index using nearby
- [Feature Request] Is there a way to limit memroy usage?
- Is there any plan to support index on MessagePack? HOT 1
- How to renew the ttl?
- Question: Is buntdb goroutine-safe? HOT 1
- Will "group by" be supported in this lib?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
š Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ššš
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ā¤ļø Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from buntdb.