I am looking to create subcollections with React Native Firebase to create a firestore structure like this:
groups
->group
->scheduledQuestionnaires
->questionnaire (fields: id, type and timestamp)
users
->user
->groups
(fields: id and name)
I have created the collections groups and users, but how can I create a subcollection scheduledQuestionnaires for every group programmatically.
I am able to add documents with fields to collections just fine, but I can't seem to find a way to create (sub)collections. Am I going the wrong way about it or am I missing something?
EDIT
To add to the answer by monsty. Here is a code snippet of what I wanted to do:
firestore()
.collection('groups')
.doc('group1/scheduledQuestionnaires/questionnaire1')
.set({
id: '1',
type: 'type',
timestamp: 'timestamp',
});
You don't need to create subcollections for every collection, because Firebase will handle it.
If you try to save a document into "/groups/group/scheduledQuestionnaires/hello/world/my_document", Firebase will create all the sub collections needed (in this case : hello and world).
Related
I'm new to symfony and the api platform and I want to develop an api with specific routes.
I'm looking to do is create a post query with nested resources to add relationships between tables.
example: I have 3 tables (users, periods, articles). I need to create a post request to add a new post with the following structure:
URL: api/:userid/:period/item
:userID = user ID
:period = Period name
name = element name
This request must create a new article in my "articles" table by adding the identifier, the name of the period and the name of the article entered as a parameter.
So my question is how do I pass multiple parameters in my path and save them in the database using the api platform?
Thanks in advance !
You can use custom routes with API platform, which allow you to create a route that correspond to a custom query => but you need to have these data before setting them in your Api platform path.
First of all, I would use the query builder to create the query you need get the data you need, then you can use your method directly in your entity (more here https://api-platform.com/docs/core/controllers/).
You can set the route you want inside of the path of the route and set the different arguments you need like this:
'path' => '/books/{id}/publication'
here id is your argument coming from your repository function.
For a project for the municipality we are creating an api.
We've chosen GraphQL as framework for the API and we've written it in C#.
The API works for normal data like strings, ints etc.
However there is a catch. We need to work with Geometry/spatial data as well. So we've 'linked' the GraphQL API to our database, which is a PostGIS/PostgreSQL database.
We want GeoJSON as output, because that is easily plottable using something like MapBox.
The view we've created within PostGIS/PostgreSQL is as follows:
CREATE VIEW pandGeoJSON AS
select row_to_json(fc)
from (
select
'FeatureCollection' as "type",
array_to_json(array_agg(f)) as "features"
from (
select
'Feature' as "type",
ST_AsGeoJSON(geom) :: json as "geometry",
(
sor_id,
status
) as "properties"
from pand INNER JOIN sor as s on pand.sor_id = s.sor_pandid
group by sor_id
) as f
) as fc;
But I can't seem to find anywhere on the internet how we would be able to get that view and use it as output of our GraphQL API. Or are we thinking the wrong way round and should we create that view within GraphQL itself?
Apparently it is quite simple. You can just call the view the same way you call a table. So you have to create them the same way as well.
Quite easy, still, if you didn't know it, you didn't know it. Finding the answer is very helpfull in those instances.
I am using Firebase Realtime Database in my react-native project. I want to save the data in below formate
Images
Category 1
Image:
"/9j/4AAQSkZJRgABAQAASABIAAD/4QBYRXhpZgAATU0AKgA...",
"/9j/4AAQSkZJRgABAQAASABIAAD/4QBYRXhpZgAATU0AKgA..."
Category 2
Image:
"/9j/4AAQSkZJRgABAQAASABIAAD/4QBYRXhpZgAATU0AKgA..."
I want to store data depend upon categories. if I select category 1 the data is overwriting the old once, but I want to add without overwriting the previous data.
Is it possible to do so?
sample code
firebase.database().ref('Images/'+this.state.selectedValue).set({
Image: this.state.imageSource,
}).then(() =>{
alert('saved')
}).catch((error) =>{
alert(JSON.stringify(error))
})
You are adding the new data to the old key so it is replacing it. You need to add a new key for every object like given below.
Images:{
Category 1:[{image1: "/9j/4AAQSkZJRgABAQAASABIAAD/4QBYRXhpZgAA..."},image2:{"jmehyrjwrjewrghwe"} ],
Category 2:[ "/9j/4AAQSkZJRgABAQAASABIAAD/4QBYRXhpZgAATU0AKgA..." ],image2:{"jmehyrjwrjewrghwe"} }
Then it will work
I've started using mobx-state-tree recently and I have a practical question.
I have a model that has a types.identifier field, this is the database id of the resource and when I query for existing stuff it gets populated.
When I am creating a new instance, though, following the example that Michel has on egghead, I need to pass an initial id to my MyModel.create() on initial state, however, this ID will only be known once I post the creation to the API and get the resulting created resource.
I have searched around for a simple crud example using mobx-state-tree but couldn't find one (suggestions?).
What is the best practice here? Should I do a `MyModel.create({ id: 'foobar' }) and weed it out when I post to the API (and update the instance once I get the response from the API)?
This is a limitation of mobx-state-tree's current design. Identifiers are immutable.
One strategy I've seen to get around this issue is to store your persistence layer's id in a separate field from your types.identifier field. You would then use a library like uuid to generate the types.identifier value:
import { v4 } from "node-uuid"
const Box = types
.model("Box", {
id: types.identifier,
name: "hal",
x: 0,
y: 0
})
const box = Box.create({ 'hal', 10, 10, id: v4() })
Is there a way to store custom application configurations on the Cumulocity backend through the c8y.sdk? I would like to store a JSON with configuration information specific to an application created using the the smart app toolkit.
You can save settings at the tenant by using c8ySettings,
BUT you have a limitation of 256 characters per value.
I'm struggling with the same problem of storing larger plugin configurations without any success.
I asked about this from cumulocity support and they said it is possible to store custom JSON under managedobjects because at the moment they dont support storing JSON to database otherwise.
So you will need "create" or "admin" rights to inventory to be able to create new managedobject. You can store values like this:
var userSettings = {
type: 'userDashboardSettings',
yourSetting: somesetting,
id: settingsId
};
c8yInventory.save(userSettings).then(function(){
//do something
});
then you can search this newly created managedobject like this:
c8yInventory.list({
type: 'userDashboardSettings',
owner: id,
pageSize: 2
}).then(function (settings) { //do something }
So this way I was for example able to save user specific settings.
To find user dashboard settings do GET to: https://yourdomain.com/inventory/managedObjects/?type=userDashboardSettings&owner=IDHERE
To Delete managedObject do DELETE to: https://yourdomain.com/inventory/managedObjects/IDHERE
To see all managedObjects do GET: https://yourdomain.com/inventory/managedObjects
Type and user are important, this is how you find the managedobject.