search about user orders and sort by date (newest first) with firebase
up vote
0
down vote
favorite
i'm have an order table in firebase like this
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
add a comment |
up vote
0
down vote
favorite
i'm have an order table in firebase like this
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
Do you want to get user id from firebase?
– DionizB
Nov 22 at 14:23
I can get it by let user = Auth.auth().currentUser uid = user.uid
– aqeel
Nov 22 at 14:37
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
i'm have an order table in firebase like this
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
i'm have an order table in firebase like this
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
ios swift firebase firebase-realtime-database
edited Nov 22 at 14:22
Doug Stevenson
67.3k87998
67.3k87998
asked Nov 22 at 14:15
aqeel
5018
5018
Do you want to get user id from firebase?
– DionizB
Nov 22 at 14:23
I can get it by let user = Auth.auth().currentUser uid = user.uid
– aqeel
Nov 22 at 14:37
add a comment |
Do you want to get user id from firebase?
– DionizB
Nov 22 at 14:23
I can get it by let user = Auth.auth().currentUser uid = user.uid
– aqeel
Nov 22 at 14:37
Do you want to get user id from firebase?
– DionizB
Nov 22 at 14:23
Do you want to get user id from firebase?
– DionizB
Nov 22 at 14:23
I can get it by let user = Auth.auth().currentUser uid = user.uid
– aqeel
Nov 22 at 14:37
I can get it by let user = Auth.auth().currentUser uid = user.uid
– aqeel
Nov 22 at 14:37
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
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
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 at 22:15
Because you're ordering/filtering bycreateDate
, and then pass in a UID. If you just want to sort oncreateDate
drop thequeryEqual(toValue:
clause:rootRef.child("orders").queryOrdered(byChild: "createDate").observe(.childAdded
. Note that unless you updated your data, you'll needcreadeDate
.
– Frank van Puffelen
Nov 22 at 22:51
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
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
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 at 22:15
Because you're ordering/filtering bycreateDate
, and then pass in a UID. If you just want to sort oncreateDate
drop thequeryEqual(toValue:
clause:rootRef.child("orders").queryOrdered(byChild: "createDate").observe(.childAdded
. Note that unless you updated your data, you'll needcreadeDate
.
– Frank van Puffelen
Nov 22 at 22:51
add a comment |
up vote
0
down vote
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
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 at 22:15
Because you're ordering/filtering bycreateDate
, and then pass in a UID. If you just want to sort oncreateDate
drop thequeryEqual(toValue:
clause:rootRef.child("orders").queryOrdered(byChild: "createDate").observe(.childAdded
. Note that unless you updated your data, you'll needcreadeDate
.
– Frank van Puffelen
Nov 22 at 22:51
add a comment |
up vote
0
down vote
up vote
0
down vote
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
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
answered Nov 22 at 14:45
Frank van Puffelen
223k26364390
223k26364390
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 at 22:15
Because you're ordering/filtering bycreateDate
, and then pass in a UID. If you just want to sort oncreateDate
drop thequeryEqual(toValue:
clause:rootRef.child("orders").queryOrdered(byChild: "createDate").observe(.childAdded
. Note that unless you updated your data, you'll needcreadeDate
.
– Frank van Puffelen
Nov 22 at 22:51
add a comment |
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 at 22:15
Because you're ordering/filtering bycreateDate
, and then pass in a UID. If you just want to sort oncreateDate
drop thequeryEqual(toValue:
clause:rootRef.child("orders").queryOrdered(byChild: "createDate").observe(.childAdded
. Note that unless you updated your data, you'll needcreadeDate
.
– Frank van Puffelen
Nov 22 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 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 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 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 at 22:51
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Do you want to get user id from firebase?
– DionizB
Nov 22 at 14:23
I can get it by let user = Auth.auth().currentUser uid = user.uid
– aqeel
Nov 22 at 14:37