How to add a new reference to a firestore object - reactjs

What I'm trying to do is to add a new reference to this object:
Just insert a new element inside "citas". This is what I have so far.
database.collection('NegociosDev').doc('Peluquerías')
.collection('Negocios').doc('PR01').collection('empleados').where('Nombre', '==','Ale')...
I guess I shouldn't use "add()" as it is used to add a new document right? Any ideas?

Indeed, you should update your document this way:
database.collection('NegociosDev').doc('Peluquerías').update({
citas: firebase.firestore.FieldValue.arrayUnion("new value")
})

Related

geoFirestore - add new document with array as one of the document data property

While i try to add new document to the DB with geoFirestore and try to set one of the property as array with DocumentReference (refers to a document location in a Firestore database) i get the following error:
FirebaseError: Function DocumentReference.set() called with invalid data. Unsupported field value: a custom object
If i set there an empty array its success.
BTW if i set there a string or number its work too
The inseration code:
await geocollection.add({
coordinates: new firebase.firestore.GeoPoint(latlng.lat, latlng.lng),
arrayOfRef: [newRef]
});
I try to use Object.asset() to the newRef but get the same result.
Thanks for the helpers.
So in a lot of cases geofirestore minimally modifies the doc you give and then passes it through to Firestore. In this case it looks like Firebase/Firestore is throwing the error, not geofirestore.
I suspect that the issue is with the reference you're using. If that reference is provided by geofirestore, it's not necessarily a DocumentReference that Firestore uses, it is a GeoDocumentReference. You'll likely want to get the actual DocumentReference from the native property:
await geocollection.add({
coordinates: new firebase.firestore.GeoPoint(latlng.lat, latlng.lng),
arrayOfRef: [newRef.native]
});
Let me know if that helps! I'm also making a few assumptions as to your code, so seeing more of what happens before you call the add method would be awesome.

ng2-smart-table display list of object

Is there a way to display a list of objects in a single table cell for ng2-smart-table? I have tried creating a renderComponent but I am getting an empty value. Another question is will the filtering and sorting still work for this?
As I understood , You have a object and you want to display that data in ng2-smart-table.
For that follow this step.
import { LocalDataSource } from 'ng2-smart-table';
source : any = LocalDataSource;
When you call API then you have to set that data in source.
this.apiService.POST({}, 'getProductList').subscribe((res) => {
console.log(res);
this.source = new LocalDataSource(res.data); // Set response as per your res.
});
As you can see I have also set one array and that array has objects of data and I have set in table.
I hope this may help you. :)

Can't get data from store.getNewRecords() after use store.add(record)

I'm new developer extjs. I want to get add new record from store after add store.add(record). i use sytax like below
var newRecord = store.getNewRecords()
console.log('newRecord',newRecord);
but i can't get new record, i got output data like this newRecord:[]
Please help me
First you need to add records to store and commit changes,then get new records.
grid_store.add({'Name':"ab",'dob':"099"})
grid_store.commitChanges();
var newRecord = grid_store.getNewRecords()
console.log('newRecord',newRecord);
});
Here is a fiddle: http://jsfiddle.net/2p78md5t/3/

How to get DataSource length in react-native?

How do I get the DataSource's length of a ListView?
Suppose I have the following declaration:
const ds = new ListView.DataSource({ rowHasChanged });
...
someObjectsDs = ds.cloneWithRows(someObjectsArray);
I've tried someObjects.length but this returns me undefined.
You can view the amount of rows to be rendered by calling
someObjectsDs.getRowCount()
Official documentation
You can either dig into the datasource object to find the data and grab the length or you can set the data as a property of the component and refer to that:
this.someObjectsArray = someObjectsArray;
someObjectsDs = ds.cloneWithRows(this.someObjectsArray);
Now you will be able to do this.someObjectsArray.length, just make sure you're updating this variable anytime you're updating the datasource.

How to get Entry Id for a Newly Created Entity in Breeze

i want to create a registration form that will be in batch with a continuation button, getting the id of the entry will help me to call the save method.
I want to immediately get the primary key of a new Entry Created using BreezeJS, Pls i need help on this.
Thanks
Not entirely sure I understand your question, but it sounds like you want to get the id of a newly saved record immediately after the save. If so then the answer below applies.
When the save promise resolves it returns both the list of saved entities as well as a keyMappings array for any entities whose ids changed as a result of the save. i.e. a mapping from temporary to real ids. i.e. (Documented here: http://www.breezejs.com/sites/all/apidocs/classes/EntityManager.html#method_saveChanges)
myEntityManager.saveChanges().then(function (saveResult) {
// entities is an array of entities that were just saved.
var entitites = saveResult.entities;
var keyMappings = saveResult.keyMappings;
keyMappings.forEach(function(km) {
var tempId = km.tempValue;
var newId = km.realValue;
});
});
On the other hand if you have an entity and you just want its 'key' you can use the EntityAspect.getKey method. (see http://www.breezejs.com/sites/all/apidocs/classes/EntityAspect.html#method_getKey)
// assume order is an order entity attached to an EntityManager.
var entityKey = order.entityAspect.getKey();

Resources