Prioritize an Object within a Firebase Query -


i have following structure in firebase database

-- user-posts ---- -kekdik4k3k5wjnc ------ title: "batman greatest hero" ------ body: "there no other hero compare here..." ---- -k34idfgklksdcxq ------ title: "superman weak" ------ body: "let's talk shoddy, overrated alien m..." 

say want query objects /user-posts node, post -kekdik4k3k5wjnc set/sorted first element. can done in firebase? if so, combined limittofirst? don't see exact functionality in documentation may have overlooked.

i'm looking avoid manipulating array myself if can it.

any input appreciated?

say have usersref node in database, , post object id, title , body in project, combine queryorderedbykey , querylimited so:

  func userpostobserver(_ completion: @escaping () -> ()) {              guard let currentuserid = auth.auth().currentuser?.uid else {                 return             }              usersref.child(currentuserid).child("posts").queryorderedbykey.querylimited(tolast: 10).observe(.childadded, with: { [weak self] (snapshot) in                  guard let title = snapshot.childsnapshot(forpath: "title").value as? string,                     let body = snapshot.childsnapshot(forpath: "body").value as? string,                     else {                         return                 }                  self?.posts.append(post(id: snapshot.key, title: title, body: body))                  completion()              }) } 


this retrieve last 10 posts specific users ordered key (firebase unique push id generated data @ data created) ordered list !

note: querylimited(tolast: 10) grab last 10 posts added in node, means grab recent posts. fired every new post added node.


Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -