search about user orders and sort by date (newest first) with firebase





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















i'm have an order table in firebase like this
enter image description here



and in my iOS app, i want to show the orders for the user which is active and want to sort them by (CreateDate) to show the newest first



i'm using this code , it's only show the user orders without sorting by date



 if   (Auth.auth().currentUser != nil) {
let user = Auth.auth().currentUser
if let user = user {
uid = user.uid

print("uid = (uid)")


// get order details
let ordersRef = rootRef.child("orders")
ordersRef.queryOrdered(byChild: "clientuid_status").queryEqual(toValue: "(uid)_0").observe(.childAdded, with: { (snapshot) -> Void in

let snabshotvalue = snapshot.value as? [String : AnyObject]
let dateorder = snabshotvalue!["orderDate"]
let tecname = snabshotvalue!["tecname"]
let theproblem = snabshotvalue!["theproblem"]
let homeadress = snabshotvalue!["homeadress"]
let clintlat = snabshotvalue!["clintlat"]
let clintlong = snabshotvalue!["clintlong"]
let clintuid = snabshotvalue!["clintuid"]
let tecuid = snabshotvalue!["tecuid"]
let tecToken = snabshotvalue!["tecToken"]
let status = snabshotvalue!["status"]
let servicetable = snabshotvalue!["servicetable"]

let snashotkey = snapshot.key as String
print("firstname: (tecname) ")

self.dateArray.append(dateorder as? String)
self.tecnameArray.append(tecname as? String)
self.problemArray.append(theproblem as? String)
self.homeadressArray.append(homeadress as? String)
self.clintlatArray.append(clintlat as? String)
self.clintlongArray.append(clintlong as? String)
self.tecuidArray.append(tecuid as? String)
self.tecTokenArray.append(tecToken as? String)
self.orderuidArray.append(snashotkey )
self.clintidArray.append(clintuid as? String)
self.statusArray.append(status as? String)
self.servicetableArray.append(servicetable as? String)

self.getTechRatin(teckUid: tecuid as! String)

self.tableView.reloadData()
})


}


i'm sent a ticket to firebase support, they told me to use this code :



    let orderOrdersByCreatedDate= (ref.child("orders").child(getUid())).queryOrdered(byChild: "createDate").queryLimited(toLast: 1)


when i try to use your code, i get this error :
Use of unresolved identifier 'getUid'



i don't know how use getUid()










share|improve this question

























  • Do you want to get user id from firebase?

    – DionizB
    Nov 22 '18 at 14:23











  • I can get it by let user = Auth.auth().currentUser uid = user.uid

    – aqeel
    Nov 22 '18 at 14:37


















0















i'm have an order table in firebase like this
enter image description here



and in my iOS app, i want to show the orders for the user which is active and want to sort them by (CreateDate) to show the newest first



i'm using this code , it's only show the user orders without sorting by date



 if   (Auth.auth().currentUser != nil) {
let user = Auth.auth().currentUser
if let user = user {
uid = user.uid

print("uid = (uid)")


// get order details
let ordersRef = rootRef.child("orders")
ordersRef.queryOrdered(byChild: "clientuid_status").queryEqual(toValue: "(uid)_0").observe(.childAdded, with: { (snapshot) -> Void in

let snabshotvalue = snapshot.value as? [String : AnyObject]
let dateorder = snabshotvalue!["orderDate"]
let tecname = snabshotvalue!["tecname"]
let theproblem = snabshotvalue!["theproblem"]
let homeadress = snabshotvalue!["homeadress"]
let clintlat = snabshotvalue!["clintlat"]
let clintlong = snabshotvalue!["clintlong"]
let clintuid = snabshotvalue!["clintuid"]
let tecuid = snabshotvalue!["tecuid"]
let tecToken = snabshotvalue!["tecToken"]
let status = snabshotvalue!["status"]
let servicetable = snabshotvalue!["servicetable"]

let snashotkey = snapshot.key as String
print("firstname: (tecname) ")

self.dateArray.append(dateorder as? String)
self.tecnameArray.append(tecname as? String)
self.problemArray.append(theproblem as? String)
self.homeadressArray.append(homeadress as? String)
self.clintlatArray.append(clintlat as? String)
self.clintlongArray.append(clintlong as? String)
self.tecuidArray.append(tecuid as? String)
self.tecTokenArray.append(tecToken as? String)
self.orderuidArray.append(snashotkey )
self.clintidArray.append(clintuid as? String)
self.statusArray.append(status as? String)
self.servicetableArray.append(servicetable as? String)

self.getTechRatin(teckUid: tecuid as! String)

self.tableView.reloadData()
})


}


i'm sent a ticket to firebase support, they told me to use this code :



    let orderOrdersByCreatedDate= (ref.child("orders").child(getUid())).queryOrdered(byChild: "createDate").queryLimited(toLast: 1)


when i try to use your code, i get this error :
Use of unresolved identifier 'getUid'



i don't know how use getUid()










share|improve this question

























  • Do you want to get user id from firebase?

    – DionizB
    Nov 22 '18 at 14:23











  • I can get it by let user = Auth.auth().currentUser uid = user.uid

    – aqeel
    Nov 22 '18 at 14:37














0












0








0








i'm have an order table in firebase like this
enter image description here



and in my iOS app, i want to show the orders for the user which is active and want to sort them by (CreateDate) to show the newest first



i'm using this code , it's only show the user orders without sorting by date



 if   (Auth.auth().currentUser != nil) {
let user = Auth.auth().currentUser
if let user = user {
uid = user.uid

print("uid = (uid)")


// get order details
let ordersRef = rootRef.child("orders")
ordersRef.queryOrdered(byChild: "clientuid_status").queryEqual(toValue: "(uid)_0").observe(.childAdded, with: { (snapshot) -> Void in

let snabshotvalue = snapshot.value as? [String : AnyObject]
let dateorder = snabshotvalue!["orderDate"]
let tecname = snabshotvalue!["tecname"]
let theproblem = snabshotvalue!["theproblem"]
let homeadress = snabshotvalue!["homeadress"]
let clintlat = snabshotvalue!["clintlat"]
let clintlong = snabshotvalue!["clintlong"]
let clintuid = snabshotvalue!["clintuid"]
let tecuid = snabshotvalue!["tecuid"]
let tecToken = snabshotvalue!["tecToken"]
let status = snabshotvalue!["status"]
let servicetable = snabshotvalue!["servicetable"]

let snashotkey = snapshot.key as String
print("firstname: (tecname) ")

self.dateArray.append(dateorder as? String)
self.tecnameArray.append(tecname as? String)
self.problemArray.append(theproblem as? String)
self.homeadressArray.append(homeadress as? String)
self.clintlatArray.append(clintlat as? String)
self.clintlongArray.append(clintlong as? String)
self.tecuidArray.append(tecuid as? String)
self.tecTokenArray.append(tecToken as? String)
self.orderuidArray.append(snashotkey )
self.clintidArray.append(clintuid as? String)
self.statusArray.append(status as? String)
self.servicetableArray.append(servicetable as? String)

self.getTechRatin(teckUid: tecuid as! String)

self.tableView.reloadData()
})


}


i'm sent a ticket to firebase support, they told me to use this code :



    let orderOrdersByCreatedDate= (ref.child("orders").child(getUid())).queryOrdered(byChild: "createDate").queryLimited(toLast: 1)


when i try to use your code, i get this error :
Use of unresolved identifier 'getUid'



i don't know how use getUid()










share|improve this question
















i'm have an order table in firebase like this
enter image description here



and in my iOS app, i want to show the orders for the user which is active and want to sort them by (CreateDate) to show the newest first



i'm using this code , it's only show the user orders without sorting by date



 if   (Auth.auth().currentUser != nil) {
let user = Auth.auth().currentUser
if let user = user {
uid = user.uid

print("uid = (uid)")


// get order details
let ordersRef = rootRef.child("orders")
ordersRef.queryOrdered(byChild: "clientuid_status").queryEqual(toValue: "(uid)_0").observe(.childAdded, with: { (snapshot) -> Void in

let snabshotvalue = snapshot.value as? [String : AnyObject]
let dateorder = snabshotvalue!["orderDate"]
let tecname = snabshotvalue!["tecname"]
let theproblem = snabshotvalue!["theproblem"]
let homeadress = snabshotvalue!["homeadress"]
let clintlat = snabshotvalue!["clintlat"]
let clintlong = snabshotvalue!["clintlong"]
let clintuid = snabshotvalue!["clintuid"]
let tecuid = snabshotvalue!["tecuid"]
let tecToken = snabshotvalue!["tecToken"]
let status = snabshotvalue!["status"]
let servicetable = snabshotvalue!["servicetable"]

let snashotkey = snapshot.key as String
print("firstname: (tecname) ")

self.dateArray.append(dateorder as? String)
self.tecnameArray.append(tecname as? String)
self.problemArray.append(theproblem as? String)
self.homeadressArray.append(homeadress as? String)
self.clintlatArray.append(clintlat as? String)
self.clintlongArray.append(clintlong as? String)
self.tecuidArray.append(tecuid as? String)
self.tecTokenArray.append(tecToken as? String)
self.orderuidArray.append(snashotkey )
self.clintidArray.append(clintuid as? String)
self.statusArray.append(status as? String)
self.servicetableArray.append(servicetable as? String)

self.getTechRatin(teckUid: tecuid as! String)

self.tableView.reloadData()
})


}


i'm sent a ticket to firebase support, they told me to use this code :



    let orderOrdersByCreatedDate= (ref.child("orders").child(getUid())).queryOrdered(byChild: "createDate").queryLimited(toLast: 1)


when i try to use your code, i get this error :
Use of unresolved identifier 'getUid'



i don't know how use getUid()







ios swift firebase firebase-realtime-database






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 14:22









Doug Stevenson

85.6k10102120




85.6k10102120










asked Nov 22 '18 at 14:15









aqeelaqeel

5019




5019













  • Do you want to get user id from firebase?

    – DionizB
    Nov 22 '18 at 14:23











  • I can get it by let user = Auth.auth().currentUser uid = user.uid

    – aqeel
    Nov 22 '18 at 14:37



















  • Do you want to get user id from firebase?

    – DionizB
    Nov 22 '18 at 14:23











  • I can get it by let user = Auth.auth().currentUser uid = user.uid

    – aqeel
    Nov 22 '18 at 14:37

















Do you want to get user id from firebase?

– DionizB
Nov 22 '18 at 14:23





Do you want to get user id from firebase?

– DionizB
Nov 22 '18 at 14:23













I can get it by let user = Auth.auth().currentUser uid = user.uid

– aqeel
Nov 22 '18 at 14:37





I can get it by let user = Auth.auth().currentUser uid = user.uid

– aqeel
Nov 22 '18 at 14:37












1 Answer
1






active

oldest

votes


















0














That last snippet of code is wrong. To sort the orders by creadeDate you need:



ordersRef.queryOrdered(byChild: "creadeDate").observe(.childAdded, ...


But Firebase Database queries can only order/filter on a single property, so that means that you can no longer filter on clientuid_status as you do now.



In many cases it is possible to combine the values you want to filter on into a single (synthetic) property. You already seem to have done this with clientuid_status, and to allow both filtering on that and ordering on date, you'll expand it to clientuid_status_creadeDate and order/filter on that.



For an example of this and other approaches, see my answer here: http://stackoverflow.com/questions/26700924/query-based-on-multiple-where-clauses-in-firebase






share|improve this answer
























  • thanks,i don't care to filter by clientuid_status, i only want to retrieve the orders which equal to clientuid_status and sort them by createDate without sort by uid or status (note: i write it wrong creadeDate) , so if i write the code like this why it's not working : rootRef.child("orders").queryOrdered(byChild: "createDate").queryEqual(toValue: "(uid)_0").observe(.childAdded, with: { (snapshot) -> Void in

    – aqeel
    Nov 22 '18 at 22:15











  • Because you're ordering/filtering by createDate, and then pass in a UID. If you just want to sort on createDate drop the queryEqual(toValue: clause: rootRef.child("orders").queryOrdered(byChild: "createDate").observe(.childAdded. Note that unless you updated your data, you'll need creadeDate.

    – Frank van Puffelen
    Nov 22 '18 at 22:51












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53432894%2fsearch-about-user-orders-and-sort-by-date-newest-first-with-firebase%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














That last snippet of code is wrong. To sort the orders by creadeDate you need:



ordersRef.queryOrdered(byChild: "creadeDate").observe(.childAdded, ...


But Firebase Database queries can only order/filter on a single property, so that means that you can no longer filter on clientuid_status as you do now.



In many cases it is possible to combine the values you want to filter on into a single (synthetic) property. You already seem to have done this with clientuid_status, and to allow both filtering on that and ordering on date, you'll expand it to clientuid_status_creadeDate and order/filter on that.



For an example of this and other approaches, see my answer here: http://stackoverflow.com/questions/26700924/query-based-on-multiple-where-clauses-in-firebase






share|improve this answer
























  • thanks,i don't care to filter by clientuid_status, i only want to retrieve the orders which equal to clientuid_status and sort them by createDate without sort by uid or status (note: i write it wrong creadeDate) , so if i write the code like this why it's not working : rootRef.child("orders").queryOrdered(byChild: "createDate").queryEqual(toValue: "(uid)_0").observe(.childAdded, with: { (snapshot) -> Void in

    – aqeel
    Nov 22 '18 at 22:15











  • Because you're ordering/filtering by createDate, and then pass in a UID. If you just want to sort on createDate drop the queryEqual(toValue: clause: rootRef.child("orders").queryOrdered(byChild: "createDate").observe(.childAdded. Note that unless you updated your data, you'll need creadeDate.

    – Frank van Puffelen
    Nov 22 '18 at 22:51
















0














That last snippet of code is wrong. To sort the orders by creadeDate you need:



ordersRef.queryOrdered(byChild: "creadeDate").observe(.childAdded, ...


But Firebase Database queries can only order/filter on a single property, so that means that you can no longer filter on clientuid_status as you do now.



In many cases it is possible to combine the values you want to filter on into a single (synthetic) property. You already seem to have done this with clientuid_status, and to allow both filtering on that and ordering on date, you'll expand it to clientuid_status_creadeDate and order/filter on that.



For an example of this and other approaches, see my answer here: http://stackoverflow.com/questions/26700924/query-based-on-multiple-where-clauses-in-firebase






share|improve this answer
























  • thanks,i don't care to filter by clientuid_status, i only want to retrieve the orders which equal to clientuid_status and sort them by createDate without sort by uid or status (note: i write it wrong creadeDate) , so if i write the code like this why it's not working : rootRef.child("orders").queryOrdered(byChild: "createDate").queryEqual(toValue: "(uid)_0").observe(.childAdded, with: { (snapshot) -> Void in

    – aqeel
    Nov 22 '18 at 22:15











  • Because you're ordering/filtering by createDate, and then pass in a UID. If you just want to sort on createDate drop the queryEqual(toValue: clause: rootRef.child("orders").queryOrdered(byChild: "createDate").observe(.childAdded. Note that unless you updated your data, you'll need creadeDate.

    – Frank van Puffelen
    Nov 22 '18 at 22:51














0












0








0







That last snippet of code is wrong. To sort the orders by creadeDate you need:



ordersRef.queryOrdered(byChild: "creadeDate").observe(.childAdded, ...


But Firebase Database queries can only order/filter on a single property, so that means that you can no longer filter on clientuid_status as you do now.



In many cases it is possible to combine the values you want to filter on into a single (synthetic) property. You already seem to have done this with clientuid_status, and to allow both filtering on that and ordering on date, you'll expand it to clientuid_status_creadeDate and order/filter on that.



For an example of this and other approaches, see my answer here: http://stackoverflow.com/questions/26700924/query-based-on-multiple-where-clauses-in-firebase






share|improve this answer













That last snippet of code is wrong. To sort the orders by creadeDate you need:



ordersRef.queryOrdered(byChild: "creadeDate").observe(.childAdded, ...


But Firebase Database queries can only order/filter on a single property, so that means that you can no longer filter on clientuid_status as you do now.



In many cases it is possible to combine the values you want to filter on into a single (synthetic) property. You already seem to have done this with clientuid_status, and to allow both filtering on that and ordering on date, you'll expand it to clientuid_status_creadeDate and order/filter on that.



For an example of this and other approaches, see my answer here: http://stackoverflow.com/questions/26700924/query-based-on-multiple-where-clauses-in-firebase







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 22 '18 at 14:45









Frank van PuffelenFrank van Puffelen

248k31396423




248k31396423













  • thanks,i don't care to filter by clientuid_status, i only want to retrieve the orders which equal to clientuid_status and sort them by createDate without sort by uid or status (note: i write it wrong creadeDate) , so if i write the code like this why it's not working : rootRef.child("orders").queryOrdered(byChild: "createDate").queryEqual(toValue: "(uid)_0").observe(.childAdded, with: { (snapshot) -> Void in

    – aqeel
    Nov 22 '18 at 22:15











  • Because you're ordering/filtering by createDate, and then pass in a UID. If you just want to sort on createDate drop the queryEqual(toValue: clause: rootRef.child("orders").queryOrdered(byChild: "createDate").observe(.childAdded. Note that unless you updated your data, you'll need creadeDate.

    – Frank van Puffelen
    Nov 22 '18 at 22:51



















  • thanks,i don't care to filter by clientuid_status, i only want to retrieve the orders which equal to clientuid_status and sort them by createDate without sort by uid or status (note: i write it wrong creadeDate) , so if i write the code like this why it's not working : rootRef.child("orders").queryOrdered(byChild: "createDate").queryEqual(toValue: "(uid)_0").observe(.childAdded, with: { (snapshot) -> Void in

    – aqeel
    Nov 22 '18 at 22:15











  • Because you're ordering/filtering by createDate, and then pass in a UID. If you just want to sort on createDate drop the queryEqual(toValue: clause: rootRef.child("orders").queryOrdered(byChild: "createDate").observe(.childAdded. Note that unless you updated your data, you'll need creadeDate.

    – Frank van Puffelen
    Nov 22 '18 at 22:51

















thanks,i don't care to filter by clientuid_status, i only want to retrieve the orders which equal to clientuid_status and sort them by createDate without sort by uid or status (note: i write it wrong creadeDate) , so if i write the code like this why it's not working : rootRef.child("orders").queryOrdered(byChild: "createDate").queryEqual(toValue: "(uid)_0").observe(.childAdded, with: { (snapshot) -> Void in

– aqeel
Nov 22 '18 at 22:15





thanks,i don't care to filter by clientuid_status, i only want to retrieve the orders which equal to clientuid_status and sort them by createDate without sort by uid or status (note: i write it wrong creadeDate) , so if i write the code like this why it's not working : rootRef.child("orders").queryOrdered(byChild: "createDate").queryEqual(toValue: "(uid)_0").observe(.childAdded, with: { (snapshot) -> Void in

– aqeel
Nov 22 '18 at 22:15













Because you're ordering/filtering by createDate, and then pass in a UID. If you just want to sort on createDate drop the queryEqual(toValue: clause: rootRef.child("orders").queryOrdered(byChild: "createDate").observe(.childAdded. Note that unless you updated your data, you'll need creadeDate.

– Frank van Puffelen
Nov 22 '18 at 22:51





Because you're ordering/filtering by createDate, and then pass in a UID. If you just want to sort on createDate drop the queryEqual(toValue: clause: rootRef.child("orders").queryOrdered(byChild: "createDate").observe(.childAdded. Note that unless you updated your data, you'll need creadeDate.

– Frank van Puffelen
Nov 22 '18 at 22:51




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53432894%2fsearch-about-user-orders-and-sort-by-date-newest-first-with-firebase%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Guess what letter conforming each word

Port of Spain

Run scheduled task as local user group (not BUILTIN)