Please try this example on browser
user.get("something").get("2020-01-01").put("some data here 01")
user.get("something").get("2020-01-02").put("some data here 02")
user.get("something").get("2020-01-03").put("some data here 03")
user.get("something").get("2020-01-04").put("some data here 04")
user.get("something").get("2020-01-05").put("some data here 05")
user.get("something").get({ ".": { "=": "2020-01-01" } }).on(console.log)
Gun still returns all the records that are available.
@amark Can you please give some clues to fix this. Thank you.
I think lex only works with map():
<html>
<script src="https://cdn.jsdelivr.net/gh/amark/gun@master/gun.js"></script>
<script src="https://cdn.jsdelivr.net/gh/amark/gun@master/sea.js"></script>
<script>
var gun = Gun();
var user = gun.get('test-' + new Date().toISOString());
user.get("something").get("2020-01-01").put("some data here 01");
user.get("something").get("2020-01-02").put("some data here 02");
user.get("something").get("2020-01-03").put("some data here 03");
user.get("something").get("2020-01-04").put("some data here 04");
user.get("something").get("2020-01-05").put("some data here 05");
user.get("something").get({ ".": { "=": "2020-01-01" } }).map().on((data, key) => {
console.log('key: ' + key + ', data: ' + JSON.stringify(data))
});
</script>
</html>
Output:
key: 2020-01-01, data: "some data here 01"
Setup: Chrome on Mac
@diatche hey somehow it doesn't work on my side. Please try this example:
user.get('lead').get(Date.now().toString()).put({some: 'data here'}) // try 5 times to put 5 records
user.get('lead').get({'.': {'<': Date.now().toString()}}).map().on(console.log) // now try to get the data
@mimiza < works as well. Consider statically writing everything out (including the callback) and then trimming down.
<html>
<script src="https://cdn.jsdelivr.net/gh/amark/gun@master/gun.js"></script>
<script src="https://cdn.jsdelivr.net/gh/amark/gun@master/sea.js"></script>
<script>
var gun = Gun();
var user = gun.get('test-' + new Date().toISOString());
user.get("something").get("2020-01-01").put("some data here 01");
user.get("something").get("2020-01-02").put("some data here 02");
user.get("something").get("2020-01-03").put("some data here 03");
user.get("something").get("2020-01-04").put("some data here 04");
user.get("something").get("2020-01-05").put("some data here 05");
user.get("something").get({ ".": { "<": "2020-01-04" } }).map().on((data, key) => {
console.log('key: ' + key + ', data: ' + JSON.stringify(data))
});
</script>
</html>
Output:
key: 2020-01-01, data: "some data here 01"
key: 2020-01-02, data: "some data here 02"
key: 2020-01-03, data: "some data here 03"
key: 2020-01-04, data: "some data here 04"
Don't worry about the reward. Just happy to help out 馃憤
@diatche but when I refresh the browser it doesn't work anymore, every time I refresh the browser. Although gun._.graph still shows that there is data in the graph. but
user.get('lead').get({'.': {'<': Date.now().toString()}}).map().on(console.log)
not showing any data. Hey thank you for the "Don't worry about the reward" part haha.
@mimiza each time you run it Gun saves data to your graph. This might be what's causing the problem.
To start from a clean state, try using a different node every time, for example:
var root = gun.get('test-' + new Date().toISOString());
Then add your test data to that node.
@diatche This is confusing. So how can I get back my data from a single source of truth? gun._.graph shows the data, but the user.get.... code above just works only when you don't refresh the browser. So confusing and I think gun is not reliable.
@amark Can you please help us little bit :( Sorry for tagging you here with knowing you are super busy.
@mimiza The above example was just to demonstrate that lex filtering works. Consider separating out data creation and listening into different scripts. Maybe run them in different browsers. You could also try to fire up a local node peer if you run into sync issues.
I haven't used gun._.graph yet so can't comment on that.
@diatche What I think I'm having is a sync issue. I start a peer and it still doesn't work.
@mimiza Hmm, try to clear browser cache/data and if you're running a node peer, delete radata folder.
@diatche I tried and tried and tried many times. If I only put some pieces of data, it's fine. But with many data, it loses the data after refresh the browser. Gun is truly not reliable as promotion.
@mimiza which version of Gun are you using? Do you have a remote peer defined? Are you using any other gun options and imports?
UPDATE: I turned on "Disable Cache" a while ago and forgot to turn it off, that caused the problem of losing data after refreshing browser. Now the data is stable, but not all lex features work.
@diatche earned the bounty. Congratulations 馃帀馃コ馃帄

Thanks again @mimiza ! Just happy to help out!
Which lex features don't work for you?