Reputation: 1638
In firestore there are collections cities
, posts
and users
. posts
have documents with reference to one user
and a city
, I wanted to retrieve all data from all posts and wrote a query:
firestore.collection('posts')
.get()
.then(snapshot => {
snapshot.docs.forEach(post => {
console.log(post.data())
});
});
although I have only one document in posts, in my console I get thousands of lines of data, all I need is something like this:
postId: {
city: "city_name",
user: {
name: "Name",
lastName: "Last"
},
description: "bla bla"
}
how can I get only needed data without all extra metadata? Here is the about 30% of output:
<code>
},
"persistence": [Circular],
"queries": ObjectMap {
"inner": Object {},
"mapKeyFn": [Function anonymous],
},
"references": ReferenceSet {
"refsByKey": SortedSet {
"comparator": [Function anonymous],
"data": SortedMap {
"comparator": [Function anonymous],
"root": LLRBEmptyNode {
"size": 0,
},
},
},
"refsByTarget": SortedSet {
"comparator": [Function anonymous],
"data": SortedMap {
"comparator": [Function anonymous],
"root": LLRBEmptyNode {
"size": 0,
},
},
},
},
"targetCount": 0,
"targetIdGenerator": TargetIdGenerator {
"generatorId": 0,
"nextId": 4,
},
},
"referenceDelegate": MemoryEagerDelegate {
"inMemoryPins": ReferenceSet {
"refsByKey": SortedSet {
"comparator": [Function anonymous],
"data": SortedMap {
"comparator": [Function anonymous],
"root": LLRBEmptyNode {
"size": 0,
},
},
},
"refsByTarget": SortedSet {
"comparator": [Function anonymous],
"data": SortedMap {
"comparator": [Function anonymous],
"root": LLRBEmptyNode {
"size": 0,
},
},
},
},
"orphanedDocuments": Set {},
"persistence": [Circular],
},
"remoteDocumentCache": MemoryRemoteDocumentCache {
"docs": SortedMap {
"comparator": [Function anonymous],
"root": LLRBEmptyNode {
"size": 0,
},
},
"indexManager": MemoryIndexManager {
"collectionParentIndex": MemoryCollectionParentIndex {
"index": Object {
"species": SortedSet {
"comparator": [Function anonymous],
"data": SortedMap {
"comparator": [Function anonymous],
"root": LLRBNode {
"color": false,
"key": ResourcePath {
"len": 0,
"offset": 5,
"segments": Array [
"projects",
"dallol",
"databases",
"(default)",
"documents",
"species",
"sigir",
],
},
"left": LLRBEmptyNode {
"size": 0,
},
"right": LLRBEmptyNode {
"size": 0,
},
"size": 1,
"value": true,
},
},
},
},
},
},
"newDocumentChanges": SortedSet {
"comparator": [Function anonymous],
"data": SortedMap {
"comparator": [Function anonymous],
"root": LLRBNode {
"color": false,
"key": DocumentKey {
"path": ResourcePath {
"len": 2,
"offset": 5,
"segments": Array [
"projects",
"dallol",
"databases",
"(default)",
"documents",
"species",
"sigir",
],
},
},
"left": LLRBEmptyNode {
"size": 0,
},
"right": LLRBEmptyNode {
"size": 0,
},
"size": 1,
"value": true,
},
},
},
"size": 0,
"sizer": [Function sizer],
},
},
"queryCache": MemoryQueryCache {
"highestSequenceNumber": 7,
"highestTargetId": 2,
"lastRemoteSnapshotVersion": SnapshotVersion {
"timestamp": Timestamp {
"nanoseconds": 715146000,
"seconds": 1564841214,
},
},
"persistence": MemoryPersistence {
"_started": true,
"clientId": "Qu1aNCEhg2urHD6JrfxZ",
"indexManager": MemoryIndexManager {
"collectionParentIndex": MemoryCollectionParentIndex {
"index": Object {
"species": SortedSet {
"comparator": [Function anonymous],
"data": SortedMap {
"comparator": [Function anonymous],
"root": LLRBNode {
"color": false,
"key": ResourcePath {
"len": 0,
"offset": 5,
"segments": Array [
"projects",
"dallol",
"databases",
"(default)",
"documents",
"species",
"sigir",
],
},
"left": LLRBEmptyNode {
"size": 0,
},
"right": LLRBEmptyNode {
"size": 0,
},
"size": 1,
"value": true,
},
},
},
},
},
},
"listenSequence": ListenSequence {
"previousValue": 9,
},
"mutationQueues": Object {
"uid:TS2JIdZl7nRD524TApPmiVFzV1l2": MemoryMutationQueue {
"batchesByDocumentKey": SortedSet {
"comparator": [Function anonymous],
"data": SortedMap {
"comparator": [Function anonymous],
"root": LLRBEmptyNode {
"size": 0,
},
},
},
"indexManager": MemoryIndexManager {
"collectionParentIndex": MemoryCollectionParentIndex {
"index": Object {
"species": SortedSet {
"comparator": [Function anonymous],
"data": SortedMap {
"comparator": [Function anonymous],
"root": LLRBNode {
"color": false,
"key": ResourcePath {
"len": 0,
"offset": 5,
"segments": Array [
"projects",
"dallol",
"databases",
"(default)",
"documents",
"species",
"sigir",
],
},
"left": LLRBEmptyNode {
"size": 0,
},
"right": LLRBEmptyNode {
"size": 0,
},
"size": 1,
"value": true,
},
},
},
},
},
},
"lastStreamToken": "",
"mutationQueue": Array [],
"nextBatchId": 1,
"referenceDelegate": MemoryEagerDelegate {
"inMemoryPins": ReferenceSet {
"refsByKey": SortedSet {
"comparator": [Function anonymous],
"data": SortedMap {
"comparator": [Function anonymous],
"root": LLRBEmptyNode {
"size": 0,
},
},
},
"refsByTarget": SortedSet {
"comparator": [Function anonymous],
"data": SortedMap {
"comparator": [Function anonymous],
"root": LLRBEmptyNode {
"size": 0,
},
},
},
},
"orphanedDocuments": Set {},
"persistence": [Circular],
},
},
},
"queryCache": [Circular],
"referenceDelegate": MemoryEagerDelegate {
"inMemoryPins": ReferenceSet {
"refsByKey": SortedSet {
"comparator": [Function anonymous],
"data": SortedMap {
"comparator": [Function anonymous],
"root": LLRBEmptyNode {
"size": 0,
},
},
},
"refsByTarget": SortedSet {
"comparator": [Function anonymous],
"data": SortedMap {
"comparator": [Function anonymous],
"root": LLRBEmptyNode {
"size": 0,
},
},
},
},
"orphanedDocuments": Set {},
"persistence": [Circular],
},
"remoteDocumentCache": MemoryRemoteDocumentCache {
"docs": SortedMap {
"comparator": [Function anonymous],
"root": LLRBEmptyNode {
"size": 0,
},
},
"indexManager": MemoryIndexManager {
"collectionParentIndex": MemoryCollectionParentIndex {
"index": Object {
"species": SortedSet {
"comparator": [Function anonymous],
"data": SortedMap {
"comparator": [Function anonymous],
"root": LLRBNode {
"color": false,
"key": ResourcePath {
"len": 0,
"offset": 5,
"segments": Array [
"projects",
"dallol",
"databases",
"(default)",
"documents",
"species",
"sigir",
],
},
"left": LLRBEmptyNode {
"size": 0,
},
"right": LLRBEmptyNode {
"size": 0,
},
"size": 1,
"value": true,
},
},
},
},
},
},
"newDocumentChanges": SortedSet {
"comparator": [Function anonymous],
"data": SortedMap {
"comparator": [Function anonymous],
"root": LLRBNode {
"color": false,
"key": DocumentKey {
"path": ResourcePath {
"len": 2,
"offset": 5,
"segments": Array [
"projects",
"dallol",
"databases",
"(default)",
"documents",
"species",
"sigir",
],
},
},
"left": LLRBEmptyNode {
"size": 0,
},
"right": LLRBEmptyNode {
"size": 0,
},
"size": 1,
"value": true,
},
},
},
"size": 0,
"sizer": [Function sizer],
},
},
"queries": ObjectMap {
"inner": Object {},
"mapKeyFn": [Function anonymous],
},
"references": ReferenceSet {
"refsByKey": SortedSet {
"comparator": [Function anonymous],
"data": SortedMap {
"comparator": [Function anonymous],
"root": LLRBEmptyNode {
"size": 0,
},
},
},
"refsByTarget": SortedSet {
"comparator": [Function anonymous],
"data": SortedMap {
"comparator": [Function anonymous],
"root": LLRBEmptyNode {
"size": 0,
},
},
},
},
"targetCount": 0,
"targetIdGenerator": TargetIdGenerator {
"generatorId": 0,
"nextId": 4,
},
},
"queryDataByTarget": Object {},
"remoteDocuments": MemoryRemoteDocumentCache {
"docs": SortedMap {
"comparator": [Function anonymous],
"root": LLRBEmptyNode {
"size": 0,
},
},
"indexManager": MemoryIndexManager {
"collectionParentIndex": MemoryCollectionParentIndex {
"index": Object {
"species": SortedSet {
"comparator": [Function anonymous],
"data": SortedMap {
"comparator": [Function anonymous],
"root": LLRBNode {
"color": false,
"key": ResourcePath {
"len": 0,
"offset": 5,
"segments": Array [
"projects",
"dallol",
"databases",
"(default)",
"documents",
"species",
"sigir",
],
},
"left": LLRBEmptyNode {
"size": 0,
},
"right": LLRBEmptyNode {
"size": 0,
},
"size": 1,
"value": true,
},
},
},
},
},
},
"newDocumentChanges": SortedSet {
"comparator": [Function anonymous],
"data": SortedMap {
"comparator": [Function anonymous],
"root": LLRBNode {
"color": false,
"key": DocumentKey {
"path": ResourcePath {
"len": 2,
"offset": 5,
"segments": Array [
"projects",
"dallol",
"databases",
"(default)",
"documents",
"species",
"sigir",
],
},
},
"left": LLRBEmptyNode {
"size": 0,
},
"right": LLRBEmptyNode {
"size": 0,
},
"size": 1,
"value": true,
},
},
},
"size": 0,
"sizer": [Function sizer],
},
},
"networkEnabled": true,
"onlineStateTracker": OnlineStateTracker {
"asyncQueue": AsyncQueue {
"delayedOperations": Array [],
"operationInProgress": true,
"tail": Promise {
"_40": 0,
"_55": Promise {
"_40": 0,
"_55": null,
"_65": 0,
"_72": null,
},
"_65": 3,
"_72": null,
},
},
"onlineStateHandler": [Function remoteStoreOnlineStateChangedHandler],
"onlineStateTimer": null,
"shouldWarnClientIsOffline": false,
"state": 1,
"watchStreamFailures": 0,
},
"syncEngine": [Circular],
"watchChangeAggregator": WatchChangeAggregator {
"metadataProvider": [Circular],
"pendingDocumentTargetMapping": SortedMap {
"comparator": [Function anonymous],
"root": LLRBEmptyNode {
"size": 0,
},
},
"pendingDocumentUpdates": SortedMap {
"comparator": [Function anonymous],
"root": LLRBEmptyNode {
"size": 0,
},
},
"pendingTargetResets": SortedSet {
"comparator": [Function primitiveComparator],
"data": SortedMap {
"comparator": [Function primitiveComparator],
"root": LLRBEmptyNode {
"size": 0,
},
},
},
"targetStates": Object {
"2": TargetState {
"_current": true,
"_hasPendingChanges": false,
"_resumeToken": "CgkIisru5e/m4wI=",
"documentChanges": SortedMap {
"comparator": [Function anonymous],
"root": LLRBEmptyNode {
"size": 0,
},
},
"pendingResponses": 0,
},
},
},
"watchStream": PersistentListenStream {
"backoff": ExponentialBackoff {
"backoffFactor": 1.5,
"currentBaseMs": 0,
"initialDelayMs": 1000,
"lastAttemptTime": 1564841257133,
"maxDelayMs": 60000,
"queue": AsyncQueue {
"delayedOperations": Array [],
"operationInProgress": true,
"tail": Promise {
"_40": 0,
"_55": Promise {
"_40": 0,
"_55": null,
"_65": 0,
"_72": null,
},
"_65": 3,
"_72": null,
},
},
"timerId": "listen_stream_connection_backoff",
"timerPromise": null,
},
"closeCount": 0,
"connection": WebChannelConnection {
"baseUrl": "https://firestore.googleapis.com",
"databaseId": DatabaseId {
"database": "(default)",
"projectId": "dallol",
},
"forceLongPolling": false,
},
"credentialsProvider": FirebaseCredentialsProvider {
"app": FirebaseAppImpl {
"INTERNAL": Object {
"addAuthTokenListener": [Function bound ],
"getToken": [Function bound ],
"getUid": [Function bound ],
"removeAuthTokenListener": [Function bound ],
},
"automaticDataCollectionEnabled_": false,
"firebase_": Object {
"INTERNAL": Object {
"ErrorFactory": [Function ErrorFactory],
"createFirebaseNamespace": [Function createFirebaseNamespace],
"createSubscribe": [Function createSubscribe],
"deepExtend": [Function deepExtend],
"extendNamespace": [Function extendNamespace],
"factories": Object {
"auth": [Function anonymous],
"database": [Function anonymous],
"firestore": [Function anonymous],
"storage": [Function factory],
},
},
},
}
</code>
Upvotes: 0
Views: 102
Reputation: 317750
With a document get(), you can't filter (reduce) the fields in it. When using mobile and web client SDKs, all get() operations return for all fields for all documents matched. If you need less data, you'll have to split the data into different documents and query them individually.
Upvotes: 1