Ionic App using Cloud Firestore - See data for all users
My data is structure as follows:
collection(people)
document (UserId1)
collection(profiles)
document (generatedId1)
name: 'Speech1'
type: 'admin'
document (UserId2)
collection(profiles)
document (generatedId2)
name: 'Client1'
type: 'client'
collection(tasks)
document (generatedId3)
date: '2018-12-30'
time: 'AM'
severity: 0
document (generatedId4)
date: '2018-12-30'
time: 'PM'
severity: 0
document (UserId3)
collection(profiles)
document (generatedId5)
name: 'Client2'
type: 'client'
collection(tasks)
document (generatedId5)
date: '2018-12-30'
time: 'AM'
severity: 0
document (generatedId6)
date: '2018-12-30'
time: 'PM'
severity: 0
This structure allows me to query the set of tasks for the logged in user with a statement like:
getTasks(){
return new Promise<any>((resolve, reject) => {
let currentUser = firebase.auth().currentUser;
this.snapshotChangesSubscription = this.afs.collection('people').doc(currentUser.uid).collection('tasks').snapshotChanges()
.subscribe(snapshots => {
resolve(snapshots);
})
});
}
However, when I login as an admin type user I would like to see data for all users so I am trying to construct and query that will in essence considered all documents in the people collection.
How can I do this?
javascript firebase ionic3 google-cloud-firestore
add a comment |
My data is structure as follows:
collection(people)
document (UserId1)
collection(profiles)
document (generatedId1)
name: 'Speech1'
type: 'admin'
document (UserId2)
collection(profiles)
document (generatedId2)
name: 'Client1'
type: 'client'
collection(tasks)
document (generatedId3)
date: '2018-12-30'
time: 'AM'
severity: 0
document (generatedId4)
date: '2018-12-30'
time: 'PM'
severity: 0
document (UserId3)
collection(profiles)
document (generatedId5)
name: 'Client2'
type: 'client'
collection(tasks)
document (generatedId5)
date: '2018-12-30'
time: 'AM'
severity: 0
document (generatedId6)
date: '2018-12-30'
time: 'PM'
severity: 0
This structure allows me to query the set of tasks for the logged in user with a statement like:
getTasks(){
return new Promise<any>((resolve, reject) => {
let currentUser = firebase.auth().currentUser;
this.snapshotChangesSubscription = this.afs.collection('people').doc(currentUser.uid).collection('tasks').snapshotChanges()
.subscribe(snapshots => {
resolve(snapshots);
})
});
}
However, when I login as an admin type user I would like to see data for all users so I am trying to construct and query that will in essence considered all documents in the people collection.
How can I do this?
javascript firebase ionic3 google-cloud-firestore
add a comment |
My data is structure as follows:
collection(people)
document (UserId1)
collection(profiles)
document (generatedId1)
name: 'Speech1'
type: 'admin'
document (UserId2)
collection(profiles)
document (generatedId2)
name: 'Client1'
type: 'client'
collection(tasks)
document (generatedId3)
date: '2018-12-30'
time: 'AM'
severity: 0
document (generatedId4)
date: '2018-12-30'
time: 'PM'
severity: 0
document (UserId3)
collection(profiles)
document (generatedId5)
name: 'Client2'
type: 'client'
collection(tasks)
document (generatedId5)
date: '2018-12-30'
time: 'AM'
severity: 0
document (generatedId6)
date: '2018-12-30'
time: 'PM'
severity: 0
This structure allows me to query the set of tasks for the logged in user with a statement like:
getTasks(){
return new Promise<any>((resolve, reject) => {
let currentUser = firebase.auth().currentUser;
this.snapshotChangesSubscription = this.afs.collection('people').doc(currentUser.uid).collection('tasks').snapshotChanges()
.subscribe(snapshots => {
resolve(snapshots);
})
});
}
However, when I login as an admin type user I would like to see data for all users so I am trying to construct and query that will in essence considered all documents in the people collection.
How can I do this?
javascript firebase ionic3 google-cloud-firestore
My data is structure as follows:
collection(people)
document (UserId1)
collection(profiles)
document (generatedId1)
name: 'Speech1'
type: 'admin'
document (UserId2)
collection(profiles)
document (generatedId2)
name: 'Client1'
type: 'client'
collection(tasks)
document (generatedId3)
date: '2018-12-30'
time: 'AM'
severity: 0
document (generatedId4)
date: '2018-12-30'
time: 'PM'
severity: 0
document (UserId3)
collection(profiles)
document (generatedId5)
name: 'Client2'
type: 'client'
collection(tasks)
document (generatedId5)
date: '2018-12-30'
time: 'AM'
severity: 0
document (generatedId6)
date: '2018-12-30'
time: 'PM'
severity: 0
This structure allows me to query the set of tasks for the logged in user with a statement like:
getTasks(){
return new Promise<any>((resolve, reject) => {
let currentUser = firebase.auth().currentUser;
this.snapshotChangesSubscription = this.afs.collection('people').doc(currentUser.uid).collection('tasks').snapshotChanges()
.subscribe(snapshots => {
resolve(snapshots);
})
});
}
However, when I login as an admin type user I would like to see data for all users so I am trying to construct and query that will in essence considered all documents in the people collection.
How can I do this?
getTasks(){
return new Promise<any>((resolve, reject) => {
let currentUser = firebase.auth().currentUser;
this.snapshotChangesSubscription = this.afs.collection('people').doc(currentUser.uid).collection('tasks').snapshotChanges()
.subscribe(snapshots => {
resolve(snapshots);
})
});
}
getTasks(){
return new Promise<any>((resolve, reject) => {
let currentUser = firebase.auth().currentUser;
this.snapshotChangesSubscription = this.afs.collection('people').doc(currentUser.uid).collection('tasks').snapshotChanges()
.subscribe(snapshots => {
resolve(snapshots);
})
});
}
javascript firebase ionic3 google-cloud-firestore
javascript firebase ionic3 google-cloud-firestore
edited Jan 3 at 18:14
Alex Mamo
44.7k82862
44.7k82862
asked Jan 1 at 4:36
user3639858user3639858
124
124
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
However, when I login as an admin type user I would like to see data for all users so I am trying to construct and query that will in essence considered all documents in the people collection.
How can I do this?
Unfortunately, you cannot using this database schema. Queries in Firestore are shallow, which means they only get items from the collection that the query is run against. There is no way to get documents from a top-level collection and other collections or subcollections in a single query. Firestore doesn't support queries across different collections in one go. A single query may only use properties of documents in a single collection. So the most simple solution I can think of, would be to add another collection in which you should add all "documents" within all subcollection that exist within all people collection -> uid -> generatedId
. So your schema might look similar to this:
Firestore-root
|
--- allDocuments (collection)
|
--- generatedId1 (document) //The unique id of the document
| |
| --- name: 'Speech1'
| |
| --- type: 'admin'
| |
| --- uid: 'UserId1'
|
--- generatedId 2(document) //The unique id of the document
|
--- name: 'Client1'
|
--- type: 'client'
|
--- uid: 'UserId2'
In order to display all those users, just attach a listener on the allDocuments
reference and get all users
objects. If you want to get all admin users, just use a Query
that looks like this:
var allDocumentsRef = db.collection("allDocuments");
var query = allDocumentsRef.where("type", "==", "admin");
add a comment |
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
});
}
});
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%2f53993035%2fionic-app-using-cloud-firestore-see-data-for-all-users%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
However, when I login as an admin type user I would like to see data for all users so I am trying to construct and query that will in essence considered all documents in the people collection.
How can I do this?
Unfortunately, you cannot using this database schema. Queries in Firestore are shallow, which means they only get items from the collection that the query is run against. There is no way to get documents from a top-level collection and other collections or subcollections in a single query. Firestore doesn't support queries across different collections in one go. A single query may only use properties of documents in a single collection. So the most simple solution I can think of, would be to add another collection in which you should add all "documents" within all subcollection that exist within all people collection -> uid -> generatedId
. So your schema might look similar to this:
Firestore-root
|
--- allDocuments (collection)
|
--- generatedId1 (document) //The unique id of the document
| |
| --- name: 'Speech1'
| |
| --- type: 'admin'
| |
| --- uid: 'UserId1'
|
--- generatedId 2(document) //The unique id of the document
|
--- name: 'Client1'
|
--- type: 'client'
|
--- uid: 'UserId2'
In order to display all those users, just attach a listener on the allDocuments
reference and get all users
objects. If you want to get all admin users, just use a Query
that looks like this:
var allDocumentsRef = db.collection("allDocuments");
var query = allDocumentsRef.where("type", "==", "admin");
add a comment |
However, when I login as an admin type user I would like to see data for all users so I am trying to construct and query that will in essence considered all documents in the people collection.
How can I do this?
Unfortunately, you cannot using this database schema. Queries in Firestore are shallow, which means they only get items from the collection that the query is run against. There is no way to get documents from a top-level collection and other collections or subcollections in a single query. Firestore doesn't support queries across different collections in one go. A single query may only use properties of documents in a single collection. So the most simple solution I can think of, would be to add another collection in which you should add all "documents" within all subcollection that exist within all people collection -> uid -> generatedId
. So your schema might look similar to this:
Firestore-root
|
--- allDocuments (collection)
|
--- generatedId1 (document) //The unique id of the document
| |
| --- name: 'Speech1'
| |
| --- type: 'admin'
| |
| --- uid: 'UserId1'
|
--- generatedId 2(document) //The unique id of the document
|
--- name: 'Client1'
|
--- type: 'client'
|
--- uid: 'UserId2'
In order to display all those users, just attach a listener on the allDocuments
reference and get all users
objects. If you want to get all admin users, just use a Query
that looks like this:
var allDocumentsRef = db.collection("allDocuments");
var query = allDocumentsRef.where("type", "==", "admin");
add a comment |
However, when I login as an admin type user I would like to see data for all users so I am trying to construct and query that will in essence considered all documents in the people collection.
How can I do this?
Unfortunately, you cannot using this database schema. Queries in Firestore are shallow, which means they only get items from the collection that the query is run against. There is no way to get documents from a top-level collection and other collections or subcollections in a single query. Firestore doesn't support queries across different collections in one go. A single query may only use properties of documents in a single collection. So the most simple solution I can think of, would be to add another collection in which you should add all "documents" within all subcollection that exist within all people collection -> uid -> generatedId
. So your schema might look similar to this:
Firestore-root
|
--- allDocuments (collection)
|
--- generatedId1 (document) //The unique id of the document
| |
| --- name: 'Speech1'
| |
| --- type: 'admin'
| |
| --- uid: 'UserId1'
|
--- generatedId 2(document) //The unique id of the document
|
--- name: 'Client1'
|
--- type: 'client'
|
--- uid: 'UserId2'
In order to display all those users, just attach a listener on the allDocuments
reference and get all users
objects. If you want to get all admin users, just use a Query
that looks like this:
var allDocumentsRef = db.collection("allDocuments");
var query = allDocumentsRef.where("type", "==", "admin");
However, when I login as an admin type user I would like to see data for all users so I am trying to construct and query that will in essence considered all documents in the people collection.
How can I do this?
Unfortunately, you cannot using this database schema. Queries in Firestore are shallow, which means they only get items from the collection that the query is run against. There is no way to get documents from a top-level collection and other collections or subcollections in a single query. Firestore doesn't support queries across different collections in one go. A single query may only use properties of documents in a single collection. So the most simple solution I can think of, would be to add another collection in which you should add all "documents" within all subcollection that exist within all people collection -> uid -> generatedId
. So your schema might look similar to this:
Firestore-root
|
--- allDocuments (collection)
|
--- generatedId1 (document) //The unique id of the document
| |
| --- name: 'Speech1'
| |
| --- type: 'admin'
| |
| --- uid: 'UserId1'
|
--- generatedId 2(document) //The unique id of the document
|
--- name: 'Client1'
|
--- type: 'client'
|
--- uid: 'UserId2'
In order to display all those users, just attach a listener on the allDocuments
reference and get all users
objects. If you want to get all admin users, just use a Query
that looks like this:
var allDocumentsRef = db.collection("allDocuments");
var query = allDocumentsRef.where("type", "==", "admin");
answered Jan 3 at 18:13
Alex MamoAlex Mamo
44.7k82862
44.7k82862
add a comment |
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.
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%2f53993035%2fionic-app-using-cloud-firestore-see-data-for-all-users%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