Update existing entity property values with array properties - google-cloud-datastore

I am using Google Cloud Datastore in my project, and have thousands of entities already. I want to update existing values of a property (which is of type String) to Array Values. Basically i want that property to now hold 2 values - existing value and corresponding new value for all entities. Can we do that? I want to avoid a new kind which has mapping of existing to new one.
ex - From id to id
10 10 20
Also i don't see Array Value API support in Entity class in GAE SDK 1.9.30. Is it added in 1.9.36?

Related

how can I transfer the string value of a variable in Azure Cosmos DB using the Bot Framework Composer V2?

To enter data into the Cosmos DB Tables, I use this addition (https://github.com/tomlm/iciclecreek.bot/tree/master/source/Libraries/Iciclecreek.Bot.Builder.Dialogs.Database.AzureStorage). The problem is that I cannot pass the value of the variable to the entity. Only the name of the variable is passed, not its content. My variable only contains a string value and is outputted for validation without any problem.
In this add-on, I use the Entity Operation block.
//Content Entity
// ${dialog.cosmos.name} - my variable whose value needs to be passed
{
"partitionKey": "KeyP2",
"rowKey": "RowKeyR1",
"nameUs": "${dialog.cosmos.name}",
"surnameus": "feleni"
}
You need to set a property with all variables before the entity operation block. And then insert this property into the Entity.
https://i.stack.imgur.com/xqo75.png

How can i generate custom IDs for objects in firebase?

Please I want to give custom IDs to my database objects in Firebase but I don't now how to do it. Firebase creates default IDs for database objects which I don't want. I want to be able to assign my own IDs to objects or the child nodes of in the database for unique identification.
Most likely you're adding the items to the database with something like:
ref.push().set("my value");
This generates a new unique key under ref and sets your value on it.
If you want to use you own key/name for the child location, add the item with:
ref.child("my key").set("my value");
You cannot customize ID of firebase object, but you can create another field with ID role.
ref.child("my_id").set("customize_id");
after that, using "Filter by key" to get exactly your object you want.
In our case: We need to have a user_id type Int and auto-increase, so we can't use default _id of firebase object, we create user_id ourself to solve this problem.

In Firebase whats the difference between push and childByAutoId

In Firebase if I'd like to create a child node with a unique ID it appears I have two options:
Push() :
Use the push() method to append data to a list in multiuser
applications. The push() method generates a unique ID every time a new
child is added to the specified Firebase reference. By using these
auto-generated keys for each new element in the list, several clients
can add children to the same location at the same time without write
conflicts. The unique ID generated by push() is based on a timestamp,
so list items are automatically ordered chronologically.
childByAutoId:
childByAutoId generates a new child location using a unique key and
returns a FIRDatabaseReference to it. This is useful when the children
of a Firebase Database location represent a list of items. The unique
key generated by childByAutoId: is prefixed with a client-generated
timestamp so that the resulting list will be chronologically-sorted.
Whats the difference?
Nevermind, it appears they are the same except they cater to different platforms:
Save Data on IOS
childByAutoId : Add to a list of data. Every time you call childByAutoId, Firebase generates a unique ID, such as user-posts/<user-id>/<unique-post-id>.
Save Data on Web
push() : Add to a list of data. Every time you call push(), Firebase generates a unique ID, such as user-posts/<user-id>/<unique-post-id>.

One to many rel in GAE using G data Store Entity

I want to create one to many relation using Google DataStore entities Something like:
Entity proj=new Entity("Project");
proj.setProperty("name","Project 1");
Now I want to associated multiple user entities with this project
Entity user1= new Entity("User");
user1.setProperty("name", "User1");
Entity user2= new Entity("User");
user2.setProperty("name","user2");
How do I associate multiple users 1&2 to same Project proj?
Set the project reference on the user entity

GAE Datastore - workaround for updating entity?

Assume:
class Contacts(db.Model):
first_name = StringProperty()
last_name = StringProperty()
phone_number = PhoneNumberProperty()
new_contact = Contacts(first_name="Homer", last_name="Simpson", phone_number = 1234566)
new_contact.put()
I am new to GAE Datastore, but per GAE Datastore Docs (see below if interested), i can't modify a single property of the entity (eg, phone_number). I have to re-declare all properties, and then put() the new entity. Omitting previously-declared properties from the new entity results in them being declared as None. Is there a workaround for this -- such as manually overriding the key-name generation function -- so the entity maintains the same key?
#
from GAE Datastore Docs:
To update an existing entity, modify the attributes of the object, then call the put() method. The object data overwrites the existing entity. The entire object is sent to the datastore with every call to put(). Note: The datastore API does not distinguish between creating a new entity and updating an existing entity. If the object's key represents an entity that exists, calling its put() method overwrites the entity.
that's not true. You need to have a way to get the contact you want and you can update just that. Using the keyname is only one way to do it. If you know the ID of filter a query to only get one entity, you can update a field from it and the put() to update it.
You could have something like:
query = Contact.all().filter('first_name', 'john').filter('last_name', 'doe')
for contact in query:
contact.phone_number = 498340594834
contact.put()
Note that that code would update any contacts with that name to that phone number. If there is more than one with that name, both are updated. Using a keyname can prevent that but you have to create more complex keys since only the first and last name might colide.

Resources