gundb - Confused about keys in gun DB -


var stallone = {stallone:{first:'sylvester',last:'stallone',gender:'male'}}; var gibson = {gibson:{first:'mel',last:'gibson',gender:'male'}}; var movies = gun.get('movies') movies.put(stallone).key('movies/action').key('movies/actors').key('movies/action/rambo')   movies.put(gibson).key('movies/action').key('movies/actors').key('movies/action/roadwarrior').key('movies/comedy');  movies.get('movies/action').val(); returns {_: object, stallone: object, gibson: object} nice.  movies.get('movies/comedy').val(); returns {_: object, stallone: object, gibson: object} erm..what sly doing here? not nice!!  gun.get('movies/comedy').val(); returns {_: object, stallone: object, gibson: object} same thing!! 

this behaviour leads couple of questions:
1) why bother creating movies ? i'm working var movies = gun.get('movies') why have create key 'movies' in again? 'movies' should prefixed automaticly.
2) if multiple keys work it's not intuitive. nice if movies.put(gibson).keys(['actors','comedy','action']).

note: happy if done tru loop. doesn't work eather

var gibsonkeys = ['actors','action','comedy','diehard'] gibsonkeys.foreach(function(key){     movies.put(gibson).key('movies/'+key);   // gun.put(gibson).key('movies/'+ key) }); 

as sidenote...i know keys strings , not real paths data ;)

answered mark nadal

a couple things note:

movies.put(data).key('foo/bar') 

is putting data on movies , keying movies 'foo/bar'. update operation, not insert operation. returned put same context (movies), not sub-document (you access sub document movies.put(data).path('stallone') example). if wanting insert record, kinda having table, try using .set - check out article: https://github.com/amark/gun/wiki/graphs goes on examples of various data types.
actually, .set better: https://medium.com/@sbeleidy/a-weekend-with-gun-a61fdcb8cc5d#.49nuy86gs
keys different tags, looks wanting this: https://github.com/psychollama/labelmaker.
keys in key/value can have multiple keys on point same thing. above module gives tags, allows take multiple different things , tag them same tag. underneath hood way done creates set (see above, think of unordered list) the tag keyed to, , you're able iterate on multiple different items in list. make sense? allowing key accept multiple keys though still idea though

however, behavior above correct key, seems want use tag system can add gun above module.


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -