Omit fields when performing Firebase query - javascript

Is it possible to omit particular fields when performing a Firebase query?
The following query:
getReferredUsers(referralId) {
this.logger.debug(`Getting referred users by referral id ${referralId}`);
if (referralId) {
return this.afs.collection('users', ref => ref.where('referredBy', '==', referralId).limit(3)).valueChanges();
}
}
Returns the following:
{
"displayName": null,
"email": "theshizy#hotmail.co.uk",
"emailVerified": true,
"firstName": "James",
"lastName": "Burton",
"photoURL": "https://i.imgur.com/LHhAQBH.jpg",
"referralId": "6O5qGmRQ",
"referredBy": "cpRcYiov",
"selectedCurrency": "GBP",
"selectedTimezone": "(UTC) Edinburgh, London",
"uid": "LjZ8TAb4ZGhgw2DGubbVosw8dkd2"
}
]
Can I cut it down further so that it only returns the following:
{
"emailVerified": true,
"firstName": "James",
"lastName": "Burton",
"photoURL": "https://i.imgur.com/LHhAQBH.jpg",
"referralId": "6O5qGmRQ",
}
]

The Firestore client-side SDKs always returns complete documents. There is no way to request only a part of the document with the client-side SDK, although the option does exist in the server-side SDKs' select methods.
If you only need a part of the information, consider creating an additional collection where each document just contains the data you need. This will also allow you to more easily secure access to the different types of data.
Also see:
How to allow only particular fields of a firestore document to be accessed publicly
How to get a list of keys in Firestore?

Related

Pull a full object from one value

I'm working on a ticket system, and I want to make a close ticket system, that will remove the ticket from the user, so I have my mongo array looking like this
{
"tickets": [{
"id": "cxZgqey2",
"subject": "fdgfdgdfgfdgfd",
"message": "gfdgfdgfdgdfg",
"ownerEmail": "soenmtherhg#gmail.com"
},
{
"id": "r4r-CnIC",
"subject": "dfdsfdsfsdfdsfdsf",
"message": "dsfdsfdfsdfdsfdsfdsfdsf",
"ownerEmail": "soenmtherhg#gmail.com"
}
]}
and I wanted to remove the entire object using only the id, how would I do this? (Using the npm module (not mongoose))
You can use the filter function in arrays and delete it passing the relevant id for that and also you can check loadash.

Get all doc data from Cloudant as opposed to id, key, value

Trying to query against my db to get all docs with all info. The db.list functionality gets the overview of the docs but does not return all the data for the docs. Currently have to get the high level data then loop through the rows and query each individual doc. There must be a better way...
Is there a way to get all docs with the full set of info for each doc?
getting:
{
"id": "0014ee0d-7551-4639-85ef-778f74365d05",
"key": "0014ee0d-7551-4639-85ef-778f74365d05",
"value": {
"rev": "59-4f01f89e12c488ba5b8aba4643982c45"
}
}
want:
{
"_id": "14fb92ad75b8694c05b98d89de6e9b2d",
"_rev": "1-6067c00b37a18ad8bab6744d258e6439",
"offeringId": "ae0146696d1d3a90fe400cc55a97a60e",
"timestamp": 1464165870848,
"srcUrl": "",
"score": 9,
...
}
The repository you linked to for nano looks like an outdated mirror. The official repository includes documentation for db.list which also includes a params object. I would double-check your version of nano, but I would guess you already have a more recent version.
You can simply add { include_docs: true } as the first argument to db.list and alongside id, key and value, you'll get a doc property that has the entire document.

Firebase linking users across application with unique identifier

I'm using firebase and my users are set up like this:
{
"firebase-account-123": {
"users": {
"simplelogin:1": {
"properties"{ "name": "john doe", "email": "user#email.com" }
"children": {
"simplelogin:2":{ "name": "user 2", "email": "user2#email.com" },
}
},
"simplelogin:2": {
"properties"{ "name": "user 2", "email": "user2#email.com", "disabled": false }
}
}
}
I use simplelogin:X and the users email across many objects in my database. I know using this to identify my users across different objects is probably a bad move.
At some point I am trying to implement the ability to change emails which means that their simplelogin ID is going to have to change along with every email property that ever linked to their email.
Does anyone have any suggestions on how I can link users to one another without have to change their data if it changes across the entire platform? I'm thinking somewhere along the lines of a unique identifier for each users. I just don't know how I would implement this.

Facebook Graph API - get page feed + full event info?

Is it possible to, in 1 request, get the feed of a page but with the full event info?
As it is now, if a shared event is posted, you only get back the link to that event, no picture or title:
{
"id": "xxx",
"from": {
"category": "Community",
"name": "xxx",
"id": "xxx"
},
"story": "xxx shared xxx's event.",
"link": "https://www.facebook.com/events/xxx/",
"actions": [
{
"name": "Comment",
"link": "https://www.facebook.com/xxx/posts/xxx"
},
{
"name": "Like",
"link": "https://www.facebook.com/xxx/posts/xxx"
}
],
"privacy": {
"value": ""
},
"type": "link",
"status_type": "shared_story",
"application": {
"name": "Links",
"id": "xxx"
},
"created_time": "2013-06-19T10:05:50+0000",
"updated_time": "2013-06-19T10:05:50+0000",
"likes": {
"data": [
{
"name": "xxx",
"id": "xxx"
}
],
"count": 1
}
}
If I understand correctly, you need to retrieve the events but you want to do it all at once with the feed because you want to retrieve the information on the feed anyway.
Before doing that, you must know that the feed doesn't contain all the events.... Once created, a link to the event is automatically shared on the page feed. It is only a reference, which can then be hidden. The event won't be displayed on the feed anymore even if it still exists.
Requesting two different objects at the same time
So, the feed doesn't have the events information and the events and posts (feed) are stored on 2 different tables. Therefore, you need to get the events independently from the feed:
The feed /PAGE_ID/feed
The events /PAGE_ID/events
And, as you wanted, Graph API allows you to do this in only one request:
/PAGE_ID?fields=feed,events
Additional fields
Note that either feed or events accept the limit and fields parameters. For example, events can be specified by:
events.limit(100).fields(location,name,owner,description,updated_time,venue)
Possible fields are given in the doc.
There is no way to get the "full info" at once. You will have to specify each field in the request. So, don't get the "full info", but just the information you really need.
There is a post from Facebook addressing this scenario using multi-queries and FQL (Facebook Query Language). This will allow you to make multiple FQL calls in one request.
https://developers.facebook.com/docs/technical-guides/fql/#multi

couchdb views tied between two databases?

Say I have several databases on my couch instance (in my case a user account database and login session database) The sessions have fields corresponding to a field in the user database. Is there a way to create a view, or make a call that encompasses this correlation, or would it just have to be done with an external script? To be more clear, here's an example.
Account db:
{
"_id": "78555fdfdd345debf427373f9dfaeca4",
...
"username" : "bob"
}
Sessions db:
{
"_id": "78555fdfdd345debf427373f9dfcd7ae",
..
"accountId": "78555fdfdd345debf427373f9dfaeca4",
"username": "bob"
}
Can I use emit or something like that to bundle together all this information in one call?
No, however a common workaround is to have a "type" attribute for documents.
For example...
Application db:
{
"_id": "account.78555fdfdd345debf427373f9dfaeca4",
"type": "account",
...
"username" : "bob"
}
{
"_id": "session.78555fdfdd345debf427373f9dfcd7ae",
"type": "session",
..
"accountId": "account.78555fdfdd345debf427373f9dfaeca4",
"username": "bob"
}
And then in your views:
map:
function (doc) {
if (doc.type=='account') {
# ...
}
}
No, unfortunately there is no way to connect data from multiple databases.
Each view is supposed to be self-contained, otherwise updating any document in 1 database will immediately need to trigger views indexes in every other database to be recalculated in all cases.

Categories

Resources