I've created an cloud firebase type database in firebase. Plz have a look at the image below. But How to access the datas from API(get)? If I use real time database, simply 'https://[PROJECT_ID].firebaseio.com/users/jack/name.json' this url gives the json data. But using cloud firebase database, I'm unable to get json data. I've tried to use "https://firestore.googleapis.com/v1beta1/EmployeeApp/name=employeeapp-66646/newsFeed/" but it doesn't work.
Here is an example of a URL for one of my databases:
https://firestore.googleapis.com/v1beta1/projects/project-8080059325282098184/databases/(default)/documents/52679469/docid
An explanation of the variable parts in here:
project-8080059325282098184 is my project ID.
(default) is the name of the database. At the moment you can't specify a name for your database, so yours will be (default) too.
52679469 is the name of my collection.
docid is the name of my document
The JSON I get back:
{
"name": "projects/project-8080059325282098184/databases/(default)/documents/52679469/docid",
"fields": {
"field1": {
"stringValue": "value1"
}
},
"createTime": "2018-10-06T14:16:24.090837Z",
"updateTime": "2018-10-06T14:16:24.090837Z"
}
In this response:
name is the full path of this document.
fields is the data of the document.
createTime and updateTime are the metadata for the document.
The following URL will do the trick:
https://firestore.googleapis.com/v1beta1/projects/employeeapp-66646/databases/(default)/documents/newsFeed
Have a look at the doc here, for detail on how to build the URL.
Related
I have a zapier account and I want to use zapier to send an email every time a new document is added to the emails collection. I am currently trying to set it up but I am running into an issue where the trigger setup is not correct or the account is not recognizing when a new document is added. It is not seeing the document that I created while setting up the zapier.
here is my firebase:
Here is the zapier account:
This is what I am getting when testing:
Your code isn't working because there is no field called createTime inside the document. The field that contains the timestamp is called timestamp. So your query should look like this:
"orderBy": [{
"field": {
"fieldPath": "timestamp"
},
"direction": "DESCENDING"
}]
So the simple answer here would be to use Firestore database, since it offers functionality to read only top level documents, but it is important for my app to use realtime database, I want to read the top level data, and only read the lower level data when user requests it specifically. I read the Realtime Database documentation and it says
So, it's not allowed 'by default'. I want to know if it is allowed any other way?
Read operations in the Firebase Realtime Database SDKs always return all data under all paths that are returned. There is no method in the SDKs that returns only the keys under a node, and not the further data under it.
I'd recommend changing your data structure to have an "index" data structure with just the keys, while also keeping your current structure. For example:
Users: {
"userId1": {
name: "...",
address: "...",
createdAt: 1932831239123,
lastSeenAt: 1932831239127,
},
"userId2": {
name: "...",
address: "...",
createdAt: 1632831239123,
lastSeenAt: 1732831239127,
}
},
UserKeys: {
"userId1": true,
"userId2": true
}
The true values in the UserKeys nodes are needed because you can't create a path without a value, but have no specific meaning.
Now you can can load just the keys, or the full profiles as needed.
Alternatively you can use the REST API and pass the shallow=true parameter.
I am trying to create a text editor app using firebase that allows users to create documents, but they can also nest a new document inside an existing document (when editing a document, they would be able to click on a button that would add a new document in the database and insert a link in the editor that redirects towards this page):
A user would be able to share a document with other users, but then they should have access to all the nested documents as well. So now I am wondering how to write the security rules to do that.
I think the best way to structure the realtime database would be to store all documents at the root, and then add a parentDocument or path property to each document:
{
"documents": {
"doc-1": {
"title":"Lorem ipsum",
"content": "...",
"path":"/",
"owner":"user-1",
"canAccess":{
"user-3":true
}
},
"doc-2": {
"title":"Dolor sit",
"content": "...",
"path":"/doc-1/",
"owner": "user-1"
"canAccess": {
"user-2":true
}
}
},
"users": {
"user-1": { ... },
"user-2": { ... },
"user-3": { ... }
}
}
↑ In the example below,
doc-2 is nested inside doc-1
user-1 can access both doc-1 and doc-2
user-2 can access doc-2 only
user-3 can access both doc-1 and doc-2
But now I do not know how to manage the security rules, because to check if a user has access to a specific document, I guess it would need to go through each of its parents (using its path or parentDocument prop). Perhaps I could also specify the canAccess prop on each document, but then I would have to update each nested document whenever a parent's canAccess prop is updated...
Any help would be greatly appreciated
In the Firebase Realtime Database model permission automatically cascades downwards. This means that once you grant a user (read or write) permission on a specific path, they can also access all data under that path. You can never revoke the permission at a lower level anymore.
So your requirement actually matches really nicely with this model, and I'd recommend just trying to implement it and reporting back if you run into problems.
I'm trying to upload data into Firebase Realtime Database I have tried first doing a POST through the API this is my Query:
Method: POST
EndPoint: https://[PROJECT_ID].firebaseio.com/users/5Vzshkdlu8W3sDSZMt9bc9SyhiF8.json
Note I'm using my Project ID
Headers: 'Content-Type': 'application/json'
Body:
{
"name": "Rene Alas",
"correo": "[Email]",
"image": "[URL to my Image]",
"title": "Albo Aficionado",
"acceso": 0
}
I tried this on Postman but it gets me an additional part:
As you can see it added a middle part between my given ID and the Data which is Auto Assigned in this particular example:
MTLim4FiFfdeZP4yPZP
Any Ideas how I can put the information underneath the given ID so it doesn't auto assign that key?
Kind Regards?
HTTP semantics say that POST creates a new resource under the location, which is what Firebase does in your situation.
If you want to write a value you specify to the location and overwrite any existing data there, that'd be a call with the PUT method.
If you want the data you pass (on a key by key basis) to be combined with data already at the location, use the PATCH method that Martin mentions.
If you want to update that node, the HTTP request method is PATCH and not POST.
This can be used to update individual childs, see the examples.
I'm using Alfresco 5.1 community Edition with Solr4 configured as Search Service and Transaction queries configured as Hybrid (Solr & DB)
When I do a search in Solr GUI from the below URL
Solr Query GUI: https://localhost:8443/solr4/#/alfresco/query
I get the search results in the below format with some ID & other info.
Solr Search Result (Results JSON truncated for readability)
{
"responseHeader": {
"status": 0,
"QTime": 25,
"params": {
"q": "testing",
"defType": "dismax",
"qt": "",
"indent": "true",
"wt": "json",
"_": "1476349027637"
}
},
...
"docs": [
{
"id": "_DEFAULT_!8000000000000040!80000000000008e3",
"_version_": 0,
"DBID": 2275
},
{
"id": "_DEFAULT_!8000000000000072!8000000000000902",
"_version_": 0,
"DBID": 2306
},
{
"id": "_DEFAULT_!8000000000000040!80000000000008ea",
"_version_": 0,
"DBID": 2282
},
{
"id": "_DEFAULT_!800000000000000b!80000000000008ef",
"_version_": 0,
"DBID": 2287
},
{
"id": "_DEFAULT_!8000000000000071!80000000000008f0",
"_version_": 0,
"DBID": 2288
},
{
"id": "_DEFAULT_!8000000000000025!80000000000008eb",
"_version_": 0,
"DBID": 2283
}
]
},
"processedDenies": false
}
I'm trying to build a UI where in these search results displayed, a user can click through to retrieve the respective document in Alfresco. Below is the Alfresco API I use to retrieve content from Alfresco.
Alfresco API URL to open a Document : http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/atom/content?id=
A sample Alfresco document ID looks like the one shown below. I don't get such ID returned in Solr4 search results.
Sample Document Id:
7edf97f4-43cf-4fe5-8099-85608776d159
Questions:
1) What is the ID returned by Solr4 ?
2) How do I get the relevant Alfresco document ID to be able to retrieve the same from the search result ?
EDIT:
Some background about my requirement to use Solr directly
Alfresco will be used to create documents based on some templates by interal users (business content administrators from Intranet typically). We've a front end web app (customer facing) which will have a Search section. When users perform a search operation with some keywords (Typically full text search), we would be invoking Solr API to search content in the documents created by Business Admins and the same results would be displayed on the Front end of Web app. When users clicks on the respective search results, the document content would be retrieved from Alfresco & displayed on the Front end webapp.
Thanks in advance.
It would be much easier to implement it as Alfresco Web Script.
With Web Scripts, you can either build your own RESTful interface
using light-weight scripting technologies such as JavaScript and
Freemarker.
Using web script you can access search root object:
search - org.alfresco.repo.jscript.Search -
Root object providing access to the various Alfresco search interfaces
such as FTS-Alfresco, Lucene, XPath, and Saved Search results
Your REST web script may be available to every user but run as admin:
<webscript>
<shortname>My Rest Query</shortname>
<url>/api/my/query</url>
<format default="json">argument</format>
<authentication runas="admin">guest</authentication>
<transaction allow="readonly">required</transaction>
</webscript>
There are many tutorials...
1) The ID returned by Solr is probably the ID of the indexed document in Solr. You can't use it with Alfresco.
2) It seems that Solr returns the DBID of the nodes. DBID is the property sys:node-dbid from aspect sys:referenceable defined in the file systemModel.xml and which refers to the database id of the node.
You can build an Alfresco repo webscript which takes this DBID as parameter and returns the document.
But as imagine said, you'd better directly ask Alfresco to execute your Solr query. It would return a list of documents with all the metadata you need, including the download URL of each document.
Adding a partial answer to your 2nd question because locating this info was hard and took quite some time. (2. How do I get the relevant Alfresco document ID to be able to retrieve the same from the search result ?)
To find the document associated with that DBID, you can use the following search syntax:
Go to Admin Tools -> Node Browser
Change query type to lucene
Enter the following search term: #sys\:node-dbid:THE_DBID_YOU_WANT_TO_FIND
For example, looking at our local solr4 error report:
{
"responseHeader":{
"status":0,
"QTime":0,
"params":{
"q":"ERROR*"}},
"response":{"numFound":2,"start":0,"docs":[
{
"id":"_DEFAULT_!800000000000008c!8000000000002289",
"_version_":0,
"DBID":4499},
...
To find that document, search for: #sys\:node-dbid:4499
You can add quotes around the numeric DBID - it works with and without them.
The '#' and the first backslash '\' (escaping the first colon) are REQUIRED - the query breaks if these are removed and an error will be logged in catalina.out.
The second colon MUST NOT include a backslash escape - it is NOT an error (nothing in the log) but no result will be found.
If necessary change the search scope from workspace://SpacesStore to archive://SpacesStore to locate docs that have been deleted.
You can join the DBID's as shown below to find them all at once (at least those in the same spaces store):
#sys\:node-dbid:1234 OR #sys\:node-dbid:2345 OR #sys\:node-dbid:...