I am new at using cloud firestore and Vue.
I am trying to use custom key, instead of it's generated Id.
I tried using set()
But, received error:
set() is not a function
Can someone help out, how to use it in Vue?
Thank you in advance
Assuming you have a ready project and imported the JS SDK and the firestore package:
import firebase from 'firebase/app';
import 'firebase/firestore';
First, declare a reference to a collection
const ref = firebase.firestore().collection('cars')
Then, you can set a new document passing an object to the set() function
ref.doc('my_custom_key').set({color: 'red'})
Related
I have a dynamodb table that was created via console and I want to enable multi-region support by adding to the list of replicationRegions using CDK.
After importing the original table using:
const table = Table.fromTableArn(this, "ImportedTable", "arn:aws:dynamodb...");
I realized I did not have access to the tables replicationRegions field as I would when creating new one.
Is there a way add to the list of replicationRegions on an imported dynamodb table using CDK?
Yes, but use cdk import instead of Table.fromTableArn.
The fromSomethingArn-type methods create *read-only* references to an external resource.* You can't use these to modify a resource. The ISomething interface constructs these methods return are useful for things like creating new permissions and targets.
The cdk import command is preview functionality to properly import existing resources into a CDK stack. A DynamoDB Table is a resource type that supports import operations. Once this one-time import completes, the "adopting" CDK stack can modify the "imported" table like any other, say, by adding replication regions.
In other words, The CDK can only modify resources it owns. To make ad-hoc modifications to an existing resource without permanently "adopting" it, use the SDKs instead.
* Earlier versions of the CDK docs did call these from... methods "importing" operations, but have been updated to use the less ambiguous term "referencing".
How to Import an existing smart contract into new collection on opensea?
It seems the function is close.
Thx
I try to find some API, but failes
Hey would like to know the reason :)
Why import the useStore function instead of importing directly the /store/index.js file
https://next.vuex.vuejs.org/guide/composition-api.html
Seems like it does the same
useStore uses inject (provide/inject api) to access the store. This means that passing the store from another file/dependency is not needed. It is preferred only because it is consistent thematically with the composition API (hooks).
I'm using TypeScript to define the data models for my documents in Firebase. When the document is being created the createdOn field will be the server timestamp sentinal, but otherwise it is a date. For example...
export interface Post<MODE extends 'create' | 'read'> {
comment: string;
createdOn: MODE extends 'create' ? FieldValue : Date;
}
I don't know how to properly define and assign to the createdOn property. First, I'm not really sure which firebase module to load the FieldValue type from. The best I could do was this and this seems a bit hokey...
import * as firebase from 'firebase';
type FieldValue = firebase.default.firestore.FieldValue;
export const SERVER_TIMESTAMP = firebase.default.firestore.FieldValue.serverTimestamp();
And then when I use it, this is what happens...
// Fails when used within cloud function
// Detected an object of type "FieldValue" that doesn't match the
// expected instance (found in field "createdOn"). Please ensure
/// that the Firestore types you are using are from the same NPM package.
post.createdOn = SERVER_TIMESTAMP;
// But this works within cloud function
post.createdOn = admin.firestore.FieldValue.serverTimestamp();
Are the types of FieldValue different when called from within a cloud function and on the client? Can I simply import this type from some module that works from both cloud functions and client?
I think this is a known limitation confusing issue with the javascript SDKs.
https://github.com/firebase/firebase-js-sdk/issues/4246
If you are creating an item in Firestore from an admin app you need to use a different "serverTimestamp" object than when creating one from a client app.
Firebase has quite a few products in their lineup so it's not too intuitive and this can cause confusion. Here you can view all of the products and you can view how to properly implement each library.
In your case it seems you're missing firestore which you can import using:
import * as firebase from 'firebase/app';
import 'firebase/firestore';
Then you are able to use the Field value like so:
const timestamp = firebase.firestore.FieldValue.serverTimestamp();
Here is more information on Field values.
I import a large amount of JSON files to my FireBase DB console with this feature:
https://github.com/firebase/firebase-import
It works well when I upload arrays with lots of objects,
but if i want to upload a new array object to existing table, it overrides the existing object instead of adding the new one.
I would be happy to find a right way to "Update" the new objects to the existing table with firebase-import or any other tool.
As pointed out by Jen, you can use the Firebase CLI to update objects in your database. Just use this command:
firebase database:update /path/to/object -d newArray.json
where:
/path/to/object - the path of the object that you want to update.
newArray.json - the json file containing the array with the new values.